index.d.ts
This file
Path
index.d.ts
37 lines · 1.7 KiB · TypeScript
Last changed by
Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738/** * 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 only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe * any time it is called with a base state * * @param currentState - the state to start with * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified * @returns The next state: a new state, or the current state if nothing was modified */export default function<S = any>( currentState: S, recipe: (draftState: S) => void): S// curried invocationsexport default function<S = any, A = any, B = any, C = any>( recipe: (draftState: S, a: A, b: B, c: C) => void): (currentState: S, a: A, b: B, c: C) => Sexport default function<S = any, A = any, B = any>( recipe: (draftState: S, a: A, b: B) => void): (currentState: S, a: A, b: B) => Sexport default function<S = any, A = any>( recipe: (draftState: S, a: A) => void): (currentState: S) => Sexport default function<S = any>( recipe: (draftState: S, ...extraArgs: any[]) => void): (currentState: S, ...extraArgs: any[]) => 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