Skip to content
Myr

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 file

Take it

Merge pull request #11 from benbraou/issue5Michel Weststratebefore adoption81d9d78

lines 1–4why, one step back
1/**
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 returned

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

line 5why, one step back
5 *

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 6–8why, one step back
6 * If only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe
7 * any time it is called with a base state8 *

Merge pull request #11 from benbraou/issue5Michel Weststratebefore adoption81d9d78

lines 9–12why, one step back
9 * @param currentState - the state to start with
10 * @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 back
13export default function<S = any>(
14 currentState: S,

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 15why, one step back
15 recipe: (draftState: S) => void

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

line 16why, one step back
16): S

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 17–29why, one step back
17// curried invocations
18export 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[]) => S

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

lines 30–36why, one step back
30
31/**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 back
37export function setAutoFreeze(autoFreeze: boolean): void