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
Merge pull request #11 from benbraou/issue5Michel Weststratebefore adoption81d9d78
lines 1–4why, 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.4 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returnedMerge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 5why, one step back5 *Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 6–8why, one step back6 * 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 *Merge pull request #11 from benbraou/issue5Michel Weststratebefore adoption81d9d78
lines 9–12why, one step back9 * @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 */Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 13–14why, one step back13export default function<S = any>(14 currentState: S,Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 15why, one step back15 recipe: (draftState: S) => voidMerge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 16why, one step back16): SMerge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 17–29why, one step back17// curried invocations18export default function<S = any, A = any, B = any, C = any>(19 recipe: (draftState: S, a: A, b: B, c: C) => void20): (currentState: S, a: A, b: B, c: C) => S21export default function<S = any, A = any, B = any>(22 recipe: (draftState: S, a: A, b: B) => void23): (currentState: S, a: A, b: B) => S24export default function<S = any, A = any>(25 recipe: (draftState: S, a: A) => void26): (currentState: S) => S27export default function<S = any>(28 recipe: (draftState: S, ...extraArgs: any[]) => void29): (currentState: S, ...extraArgs: any[]) => SMerge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 30–36why, one step back3031/**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 */Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 37why, one step back37export function setAutoFreeze(autoFreeze: boolean): void