Skip to content
Myr

immer.d.ts

This file

Path

src/immer.d.ts

43 lines · 1.8 KiB · TypeScript

Last changed by

Added flow types, implements #34Michel Weststratebefore adoption452e755

History of this file

Take it

Added flow types, implements #34Michel Weststratebefore adoption452e755

lines 1–43why, 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 returned5 *6 * 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 *9 * @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 */13export default function<S = any>(14 currentState: S,15 recipe: (draftState: S) => void16): S17// 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[]) => S3031/**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 */37export function setAutoFreeze(autoFreeze: boolean): void3839/**40 * Manually override whether proxies should be used.41 * By default done by using feature detection42 */43export function setUseProxies(useProxies: boolean): void