immer.js.flow
This file
Path
src/immer.js.flow
88 lines · 3.4 KiB
Last changed by
Merge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2
History of this fileTake it
Merge pull request #85 from marcins/issue-80/fix-flow-typesMichel Weststratebefore adoption4d9d4d8
lines 1–2why, one step back1// @flow2Merge branch 'patches'Michel Weststratebefore adoption2513fb8
lines 3–10why, one step back3export interface Patch {4 op: "replace" | "remove" | "add",5 path: (string|number)[],6 value?: any7}89export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void10`produce` is now exported as both default and name export. Implements #136Michel Weststratebefore adoption05e3015
lines 11–26why, one step back11interface IProduce {12 /**13 * Immer takes a state, and runs a function against it.14 * That function can freely mutate the state, as it will create copies-on-write.15 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned.16 *17 * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe18 * any time it is called with the current state.19 *20 * @param currentState - the state to start with21 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified22 * @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 undefined23 * @returns The next state: a new state, or the current state if nothing was modified24 */25 <S>(26 currentState: S,Merge branch 'patches'Michel Weststratebefore adoption2513fb8
lines 27–28why, one step back27 recipe: (draftState: S) => S | void,28 patchListener?: PatchListener`produce` is now exported as both default and name export. Implements #136Michel Weststratebefore adoption05e3015
lines 29–71why, one step back29 ): S;30 // curried invocations with inital state31 <S, A, B, C>(32 recipe: (draftState: S, a: A, b: B, c: C) => S | void,33 initialState: S34 ): (currentState: S | void, a: A, b: B, c: C) => S;35 <S, A, B>(36 recipe: (draftState: S, a: A, b: B) => S | void,37 initialState: S38 ): (currentState: S | void, a: A, b: B) => S;39 <S, A>(40 recipe: (draftState: S, a: A) => S | void,41 initialState: S42 ): (currentState: S | void, a: A) => S;43 <S>(44 recipe: (draftState: S) => S | void,45 initialState: S46 ): (currentState: S | void) => S;47 <S>(48 recipe: (draftState: S, ...extraArgs: any[]) => S | void,49 initialState: S50 ): (currentState: S | void, ...extraArgs: any[]) => S;51 // curried invocations without inital state52 <S, A, B, C>(53 recipe: (draftState: S, a: A, b: B, c: C) => S | void54 ): (currentState: S, a: A, b: B, c: C) => S;55 <S, A, B>(56 recipe: (draftState: S, a: A, b: B) => S | void57 ): (currentState: S, a: A, b: B) => S;58 <S, A>(59 recipe: (draftState: S, a: A) => S | void60 ): (currentState: S, a: A) => S;61 <S>(62 recipe: (draftState: S) => S | void63 ): (currentState: S) => S;64 <S>(65 recipe: (draftState: S, ...extraArgs: any[]) => S | void66 ): (currentState: S, ...extraArgs: any[]) => S;67}6869declare export var produce: IProduce70declare export default IProduce71Added flow types, implements #34Michel Weststratebefore adoption737e556
lines 72–75why, one step back72/**73 * Automatically freezes any state trees generated by immer.74 * This protects against accidental modifications of the state tree outside of an immer function.75 * 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 76why, one step back76 * By default it is turned on during local development, and turned off in production.Added flow types, implements #34Michel Weststratebefore adoption737e556
lines 77–84why, one step back77 */78declare export function setAutoFreeze(autoFreeze: boolean): void7980/**81 * Manually override whether proxies should be used.82 * By default done by using feature detection83 */84declare export function setUseProxies(useProxies: boolean): voidMerge branch 'patches'Michel Weststratebefore adoption2513fb8
lines 85–86why, one step back8586declare export function applyPatches<S>(state: S, patches: Patch[]): SMerge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2
lines 87–88why, one step back8788declare export function original<S>(value: S): ?S