Skip to content
Myr

immer.js.flow

This file

Path

src/immer.js.flow

75 lines · 3.0 KiB

Last changed by

`produce` is now exported as both default and name export. Implements #136Michel Weststratebefore adoption05e3015

History of this file

Take it

Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8

lines 1–2why, one step back
1// @flow
2

`produce` is now exported as both default and name export. Implements #136Michel Weststratebefore adoption05e3015

lines 3–62why, one step back
3interface IProduce {
4 /**5 * Immer takes a state, and runs a function against it.6 * That function can freely mutate the state, as it will create copies-on-write.7 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned.8 *9 * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe10 * any time it is called with the current state.11 *12 * @param currentState - the state to start with13 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified14 * @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 undefined15 * @returns The next state: a new state, or the current state if nothing was modified16 */17 <S>(18 currentState: S,19 recipe: (draftState: S) => S | void20 ): S;21 // curried invocations with inital state22 <S, A, B, C>(23 recipe: (draftState: S, a: A, b: B, c: C) => S | void,24 initialState: S25 ): (currentState: S | void, a: A, b: B, c: C) => S;26 <S, A, B>(27 recipe: (draftState: S, a: A, b: B) => S | void,28 initialState: S29 ): (currentState: S | void, a: A, b: B) => S;30 <S, A>(31 recipe: (draftState: S, a: A) => S | void,32 initialState: S33 ): (currentState: S | void, a: A) => S;34 <S>(35 recipe: (draftState: S) => S | void,36 initialState: S37 ): (currentState: S | void) => S;38 <S>(39 recipe: (draftState: S, ...extraArgs: any[]) => S | void,40 initialState: S41 ): (currentState: S | void, ...extraArgs: any[]) => S;42 // curried invocations without inital state43 <S, A, B, C>(44 recipe: (draftState: S, a: A, b: B, c: C) => S | void45 ): (currentState: S, a: A, b: B, c: C) => S;46 <S, A, B>(47 recipe: (draftState: S, a: A, b: B) => S | void48 ): (currentState: S, a: A, b: B) => S;49 <S, A>(50 recipe: (draftState: S, a: A) => S | void51 ): (currentState: S, a: A) => S;52 <S>(53 recipe: (draftState: S) => S | void54 ): (currentState: S) => S;55 <S>(56 recipe: (draftState: S, ...extraArgs: any[]) => S | void57 ): (currentState: S, ...extraArgs: any[]) => S;58}5960declare export var produce: IProduce61declare export default IProduce62

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 63–66why, one step back
63/**
64 * Automatically freezes any state trees generated by immer.65 * This protects against accidental modifications of the state tree outside of an immer function.66 * This comes with a performance impact, so it is recommended to disable this option in production.

Merge pull request #87 from apostolos/patch-1Michel Weststratebefore adoptiondc5d942

line 67why, one step back
67 * By default it is turned on during local development, and turned off in production.

Added flow types, implements #34Michel Weststratebefore adoption737e556

lines 68–75why, one step back
68 */
69declare export function setAutoFreeze(autoFreeze: boolean): void7071/**72 * Manually override whether proxies should be used.73 * By default done by using feature detection74 */75declare export function setUseProxies(useProxies: boolean): void