Skip to content
Myr

immer.js.flow

This file

Path

src/immer.js.flow

45 lines · 1.9 KiB

Last changed by

Merge branch 'flow-fixes'Michel Weststratebefore adoptionc8b61f6

History of this file

Take it

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

lines 1–2why, one step back
1// @flow
2

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 3–14why, one step back
3/**
4 * Immer takes a state, and runs a function against it.5 * That function can freely mutate the state, as it will create copies-on-write.6 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned7 *8 * If only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe9 * any time it is called with a base state10 *11 * @param currentState - the state to start with12 * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified13 * @returns The next state: a new state, or the current state if nothing was modified14 */

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

line 15why, one step back
15declare export default function produce<S>(

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 16–19why, one step back
16 currentState: S,
17 recipe: (draftState: S) => void18): S19// curried invocations

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

line 20why, one step back
20declare export default function produce<S, A, B, C>(

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 21–22why, one step back
21 recipe: (draftState: S, a: A, b: B, c: C) => void
22): (currentState: S, a: A, b: B, c: C) => S

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

line 23why, one step back
23declare export default function produce<S, A, B>(

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 24–25why, one step back
24 recipe: (draftState: S, a: A, b: B) => void
25): (currentState: S, a: A, b: B) => S

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

line 26why, one step back
26declare export default function produce<S, A>(

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 27–28why, one step back
27 recipe: (draftState: S, a: A) => void
28): (currentState: S) => S

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

line 29why, one step back
29declare export default function produce<S>(

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 30–45why, one step back
30 recipe: (draftState: S, ...extraArgs: any[]) => void
31): (currentState: S, ...extraArgs: any[]) => S3233/**34 * Automatically freezes any state trees generated by immer.35 * This protects against accidental modifications of the state tree outside of an immer function.36 * This comes with a performance impact, so it is recommended to disable this option in production.37 * It is by default enabled.38 */39declare export function setAutoFreeze(autoFreeze: boolean): void4041/**42 * Manually override whether proxies should be used.43 * By default done by using feature detection44 */45declare export function setUseProxies(useProxies: boolean): void