immer.d.ts
This file
Path
src/immer.d.ts
83 lines · 3.8 KiB · TypeScript
Last changed by
Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
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.Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
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 *Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
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 withMerge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
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,Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 16why, one step back16 recipe: (this: S, draftState: S) => void | SAdded flow types, implements #34Michel Weststratebefore adoption737e556
line 17why, one step back17): SImproved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 18–20why, one step back1819// curried invocations with default initial state20// 0 additional argumentsAdded flow types, implements #34Michel Weststratebefore adoption737e556
line 21why, one step back21export default function<S = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 22why, one step back22 recipe: (this: S, draftState: S) => void | S,Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 23–25why, one step back23 initialState: S24): (currentState: S | undefined) => S25// 1 additional argument of type AMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
line 26why, one step back26export default function<S = any, A = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 27why, one step back27 recipe: (this: S, draftState: S, a: A) => void | S,Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 28–30why, one step back28 initialState: S29): (currentState: S | undefined, a: A) => S30// 2 additional arguments of types A and BMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
line 31why, one step back31export default function<S = any, A = any, B = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 32why, one step back32 recipe: (this: S, draftState: S, a: A, b: B) => void | S,Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 33–35why, one step back33 initialState: S34): (currentState: S | undefined, a: A, b: B) => S35// 3 additional arguments of types A, B and CMerge pull request #99 from kompot/masterMichel Weststratebefore adoption27d09f6
line 36why, one step back36export default function<S = any, A = any, B = any, C = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 37why, one step back37 recipe: (this: S, draftState: S, a: A, b: B, c: C) => void | S,Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 38–43why, one step back38 initialState: S39): (currentState: S | undefined, a: A, b: B, c: C) => S40// any number of additional arguments, but with loss of type safety41// this may be alleviated if "variadic kinds" makes it into Typescript:42// https://github.com/Microsoft/TypeScript/issues/545343export default function<S = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 44why, one step back44 recipe: (this: S, draftState: S, ...extraArgs: any[]) => void | S,Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 45–46why, one step back45 initialState: S46): (currentState: S | undefined, ...extraArgs: any[]) => SAdded flow types, implements #34Michel Weststratebefore adoption737e556
line 47why, one step back47Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 48–50why, one step back48// curried invocations without default initial state49// 0 additional arguments50export default function<S = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 51why, one step back51 recipe: (this: S, draftState: S) => void | SImproved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 52–54why, one step back52): (currentState: S) => S53// 1 additional argument of type A54export default function<S = any, A = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 55why, one step back55 recipe: (this: S, draftState: S, a: A) => void | SImproved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 56–58why, one step back56): (currentState: S, a: A) => S57// 2 additional arguments of types A and B58export default function<S = any, A = any, B = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 59why, one step back59 recipe: (this: S, draftState: S, a: A, b: B) => void | SImproved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 60–62why, one step back60): (currentState: S, a: A, b: B) => S61// 3 additional arguments of types A, B and C62export default function<S = any, A = any, B = any, C = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 63why, one step back63 recipe: (this: S, draftState: S, a: A, b: B, c: C) => void | SImproved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
lines 64–68why, one step back64): (currentState: S, a: A, b: B, c: C) => S65// any number of additional arguments, but with loss of type safety66// this may be alleviated if "variadic kinds" makes it into Typescript:67// https://github.com/Microsoft/TypeScript/issues/545368export default function<S = any>(Merge pull request #131 from dmorosinotto/patch_dtsMichel Weststratebefore adoption2cd32e0
line 69why, one step back69 recipe: (this: S, draftState: S, ...extraArgs: any[]) => void | SImproved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52
line 70why, one step back70): (currentState: S, ...extraArgs: any[]) => SAdded flow types, implements #34Michel Weststratebefore adoption737e556
lines 71–83why, one step back71/**72 * Automatically freezes any state trees generated by immer.73 * This protects against accidental modifications of the state tree outside of an immer function.74 * This comes with a performance impact, so it is recommended to disable this option in production.75 * It is by default enabled.76 */77export function setAutoFreeze(autoFreeze: boolean): void7879/**80 * Manually override whether proxies should be used.81 * By default done by using feature detection82 */83export function setUseProxies(useProxies: boolean): void