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 fileTake it
Added flow types, implements #34Michel Weststratebefore adoption737e556
lines 1–3why, one step back1/**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 back4 * 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 back5 *resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c
lines 6–7why, one step back6 * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe7 * any time it is called with the current state.Added flow types, implements #34Michel Weststratebefore adoption737e556
lines 8–9why, one step back8 *9 * @param currentState - the state to start withresolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c
lines 10–11why, one step back10 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified11 * @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 undefinedAdded flow types, implements #34Michel Weststratebefore adoption737e556
lines 12–15why, one step back12 * @returns The next state: a new state, or the current state if nothing was modified13 */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 back16 recipe: (this: S, draftState: S) => voidAdded flow types, implements #34Michel Weststratebefore adoption737e556
lines 17–19why, one step back17): S18// curried invocations19export default function<S = any>(resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c
lines 20–21why, one step back20 recipe: (this: S, draftState: S, ...extraArgs: any[]) => void,21 initialState?: SAdded flow types, implements #34Michel Weststratebefore adoption737e556
line 22why, one step back22): (currentState: S, ...extraArgs: any[]) => SMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
line 23why, one step back23export default function<S = any, A = any>(resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c
lines 24–25why, one step back24 recipe: (this: S, draftState: S, a: A) => void,25 initialState?: SMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
lines 26–27why, one step back26): (currentState: S, a: A) => S27export 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 back28 recipe: (this: S, draftState: S, a: A, b: B) => void,29 initialState?: SMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
lines 30–31why, one step back30): (currentState: S, a: A, b: B) => S31export 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 back32 recipe: (this: S, draftState: S, a: A, b: B, c: C) => void,33 initialState?: SMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
line 34why, one step back34): (currentState: S, a: A, b: B, c: C) => SAdded flow types, implements #34Michel Weststratebefore adoption737e556
lines 35–48why, one step back3536/**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