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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849/** * Immer takes a state, and runs a function against it. * That function can freely mutate the state, as it will create copies-on-write. * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned. * * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe * any time it is called with the current state. * * @param currentState - the state to start with * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified * @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 * @returns The next state: a new state, or the current state if nothing was modified */export default function<S = any>( currentState: S, recipe: (this: S, draftState: S) => void): S// curried invocationsexport default function<S = any>( recipe: (this: S, draftState: S, ...extraArgs: any[]) => void, initialState?: S): (currentState: S, ...extraArgs: any[]) => Sexport default function<S = any, A = any>( recipe: (this: S, draftState: S, a: A) => void, initialState?: S): (currentState: S, a: A) => Sexport default function<S = any, A = any, B = any>( recipe: (this: S, draftState: S, a: A, b: B) => void, initialState?: S): (currentState: S, a: A, b: B) => Sexport default function<S = any, A = any, B = any, C = any>( recipe: (this: S, draftState: S, a: A, b: B, c: C) => void, initialState?: S): (currentState: S, a: A, b: B, c: C) => S
/** * Automatically freezes any state trees generated by immer. * This protects against accidental modifications of the state tree outside of an immer function. * This comes with a performance impact, so it is recommended to disable this option in production. * It is by default enabled. */export function setAutoFreeze(autoFreeze: boolean): void
/** * Manually override whether proxies should be used. * By default done by using feature detection */export function setUseProxies(useProxies: boolean): void