Skip to content
Myr

immer.d.ts

This file

Path

src/immer.d.ts

43 lines · 1.9 KiB · TypeScript

Last changed by

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

History of this file

Take it

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 1–14why, 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.4 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned5 *6 * If only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe7 * any time it is called with a base state8 *9 * @param currentState - the state to start with10 * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified11 * @returns The next state: a new state, or the current state if nothing was modified12 */13export default function<S = any>(14 currentState: S,

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

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 16–18why, one step back
16): S
17// curried invocations18export default function<S = any, A = any, B = any, C = any>(

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

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

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

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

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

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

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

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

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

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

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

Added flow types, implements #34Michel Weststratebefore adoption737e556

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