immer.js.flow
This file
Path
src/immer.js.flow
50 lines · 2.2 KiB
Last changed by
resolve #111: allow passing initial state to curried producer functionPatrick Kerschbaumbefore adoption202d54c
History of this fileTake it
1// @flow23/**4 * Immer takes a state, and runs a function against it.5 * That function can freely mutate the state, as it will create copies-on-write.6 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned.7 *8 * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe9 * any time it is called with the current state.10 *11 * @param currentState - the state to start with12 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified13 * @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 undefined14 * @returns The next state: a new state, or the current state if nothing was modified15 */16declare export default function produce<S>(17 currentState: S,18 recipe: (draftState: S) => void19): S20// curried invocations21declare export default function produce<S, A, B, C>(22 recipe: (draftState: S, a: A, b: B, c: C) => void,23 initialState?: S24): (currentState: S, a: A, b: B, c: C) => S25declare export default function produce<S, A, B>(26 recipe: (draftState: S, a: A, b: B) => void,27 initialState?: S28): (currentState: S, a: A, b: B) => S29declare export default function produce<S, A>(30 recipe: (draftState: S, a: A) => void,31 initialState?: S32): (currentState: S) => S33declare export default function produce<S>(34 recipe: (draftState: S, ...extraArgs: any[]) => void,35 initialState?: S36): (currentState: S, ...extraArgs: any[]) => S3738/**39 * Automatically freezes any state trees generated by immer.40 * This protects against accidental modifications of the state tree outside of an immer function.41 * This comes with a performance impact, so it is recommended to disable this option in production.42 * By default it is turned on during local development, and turned off in production.43 */44declare export function setAutoFreeze(autoFreeze: boolean): void4546/**47 * Manually override whether proxies should be used.48 * By default done by using feature detection49 */50declare export function setUseProxies(useProxies: boolean): void