Skip to content
Myr

immer.js.flow

This file

Path

src/immer.js.flow

69 lines · 3.1 KiB

Last changed by

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

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–5why, 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.

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

line 6why, one step back
6 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned.

Added flow types, implements #34Michel Weststratebefore adoption737e556

line 7why, one step back
7 *

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

lines 8–9why, one step back
8 * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe
9 * any time it is called with the current state.

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 10–11why, one step back
10 *
11 * @param currentState - the state to start with

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

lines 12–13why, one step back
12 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified
13 * @param initialState - if a curried function is created and this argument was given, it will be used as fallback if the curried function is called with a state of undefined

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 14–15why, one step back
14 * @returns The next state: a new state, or the current state if nothing was modified
15 */

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

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 17–19why, one step back
17 currentState: S,
18 recipe: (draftState: S) => void19): S

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

line 20why, one step back
20// curried invocations with inital state

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

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

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

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

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

lines 23–24why, one step back
23 initialState: S
24): (currentState: S | void, a: A, b: B, c: C) => S

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

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

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

line 26why, one step back
26 recipe: (draftState: S, a: A, b: B) => void,

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

lines 27–28why, one step back
27 initialState: S
28): (currentState: S | void, a: A, b: B) => 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, A>(

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

line 30why, one step back
30 recipe: (draftState: S, a: A) => void,

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

lines 31–32why, one step back
31 initialState: S
32): (currentState: S | void, a: A) => S

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

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

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

lines 34–37why, one step back
34 recipe: (draftState: S) => void,
35 initialState: S36): (currentState: S | void) => S37declare export default function produce<S>(

Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption8e42349

line 38why, one step back
38 recipe: (draftState: S, ...extraArgs: any[]) => void,

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptionaef96d2

lines 39–55why, one step back
39 initialState: S
40): (currentState: S | void, ...extraArgs: any[]) => S41// curried invocations without inital state42declare export default function produce<S, A, B, C>(43 recipe: (draftState: S, a: A, b: B, c: C) => void44): (currentState: S, a: A, b: B, c: C) => S45declare export default function produce<S, A, B>(46 recipe: (draftState: S, a: A, b: B) => void47): (currentState: S, a: A, b: B) => S48declare export default function produce<S, A>(49 recipe: (draftState: S, a: A) => void50): (currentState: S, a: A) => S51declare export default function produce<S>(52 recipe: (draftState: S) => void53): (currentState: S) => S54declare export default function produce<S>(55 recipe: (draftState: S, ...extraArgs: any[]) => void

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 56–60why, one step back
56): (currentState: S, ...extraArgs: any[]) => S
57/**58 * Automatically freezes any state trees generated by immer.59 * This protects against accidental modifications of the state tree outside of an immer function.60 * This comes with a performance impact, so it is recommended to disable this option in production.

Merge pull request #87 from apostolos/patch-1Michel Weststratebefore adoptiondc5d942

line 61why, one step back
61 * By default it is turned on during local development, and turned off in production.

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 62–69why, one step back
62 */
63declare export function setAutoFreeze(autoFreeze: boolean): void6465/**66 * Manually override whether proxies should be used.67 * By default done by using feature detection68 */69declare export function setUseProxies(useProxies: boolean): void