Skip to content
Myr

immer.d.ts

This file

Path

src/immer.d.ts

48 lines · 2.2 KiB · TypeScript

Last changed by

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

History of this file

Take it

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 1–3why, one step back
1/**
2 * Immer takes a state, and runs a function against it.3 * That function can freely mutate the state, as it will create copies-on-write.

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

line 4why, one step back
4 * 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 5why, one step back
5 *

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

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

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

lines 10–11why, one step back
10 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified
11 * @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 12–15why, one step back
12 * @returns The next state: a new state, or the current state if nothing was modified
13 */14export default function<S = any>(15 currentState: S,

Immer now changes the context (`this`) of producer functions by default to the draft stateMichel Weststratebefore adoption3a9d6d1

line 16why, one step back
16 recipe: (this: S, draftState: S) => void

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 17–19why, one step back
17): S
18// curried invocations19export default function<S = any>(

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

lines 20–21why, one step back
20 recipe: (this: S, draftState: S, ...extraArgs: any[]) => void,
21 initialState?: S

Added flow types, implements #34Michel Weststratebefore adoption737e556

line 22why, one step back
22): (currentState: S, ...extraArgs: any[]) => S

Merge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6

line 23why, one step back
23export default function<S = any, A = any>(

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

lines 24–25why, one step back
24 recipe: (this: S, draftState: S, a: A) => void,
25 initialState?: S

Merge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6

lines 26–27why, one step back
26): (currentState: S, a: A) => S
27export default function<S = any, A = any, B = any>(

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

lines 28–29why, one step back
28 recipe: (this: S, draftState: S, a: A, b: B) => void,
29 initialState?: S

Merge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6

lines 30–31why, one step back
30): (currentState: S, a: A, b: B) => S
31export default function<S = any, A = any, B = any, C = any>(

resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c

lines 32–33why, one step back
32 recipe: (this: S, draftState: S, a: A, b: B, c: C) => void,
33 initialState?: S

Merge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6

line 34why, one step back
34): (currentState: S, a: A, b: B, c: C) => S

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 35–48why, one step back
35
36/**37 * Automatically freezes any state trees generated by immer.38 * This protects against accidental modifications of the state tree outside of an immer function.39 * This comes with a performance impact, so it is recommended to disable this option in production.40 * It is by default enabled.41 */42export function setAutoFreeze(autoFreeze: boolean): void4344/**45 * Manually override whether proxies should be used.46 * By default done by using feature detection47 */48export function setUseProxies(useProxies: boolean): void