index.js.flow
This file
Path
src/types/index.js.flow
85 lines · 3.4 KiB
Last changed by
fix: added flow typings for new API's introduced in v6. Fixes #570Michel Weststratebefore adoption0ddddfc
History of this fileTake it
fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 1–10why, one step back1// @flow23export interface Patch {4 op: "replace" | "remove" | "add",5 path: (string|number)[],6 value?: any7}89export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void10fix: improve flow typesMichel Weststratebefore adoption427040c
line 11why, one step back11type Base = {...} | Array<any> | Map<any> | Set<any>;fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 12–25why, one step back12interface IProduce {13 /**14 * Immer takes a state, and runs a function against it.15 * That function can freely mutate the state, as it will create copies-on-write.16 * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned.17 *18 * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe19 * any time it is called with the current state.20 *21 * @param currentState - the state to start with22 * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified23 * @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 undefined24 * @returns The next state: a new state, or the current state if nothing was modified25 */fix: improve flow typesMichel Weststratebefore adoption427040c
line 26why, one step back26 <S: Base>(fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 27–31why, one step back27 currentState: S,28 recipe: (draftState: S) => S | void,29 patchListener?: PatchListener30 ): S;31 // curried invocations with inital statefix: improve flow typesMichel Weststratebefore adoption427040c
lines 32–33why, one step back32 <S: Base, A = void, B = void, C = void>(33 recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void,fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
line 34why, one step back34 initialState: Sfix: improve flow typesMichel Weststratebefore adoption427040c
line 35why, one step back35 ): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => S;fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
line 36why, one step back36 // curried invocations without inital statefix: improve flow typesMichel Weststratebefore adoption427040c
lines 37–39why, one step back37 <S: Base, A = void, B = void, C = void>(38 recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void39 ): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S;fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 40–80why, one step back40}4142declare export var produce: IProduce43declare export default IProduce4445declare export var nothing: typeof undefined4647declare export var immerable: Symbol4849/**50 * Automatically freezes any state trees generated by immer.51 * This protects against accidental modifications of the state tree outside of an immer function.52 * This comes with a performance impact, so it is recommended to disable this option in production.53 * By default it is turned on during local development, and turned off in production.54 */55declare export function setAutoFreeze(autoFreeze: boolean): void5657/**58 * Manually override whether proxies should be used.59 * By default done by using feature detection60 */61declare export function setUseProxies(useProxies: boolean): void6263declare export function applyPatches<S>(state: S, patches: Patch[]): S6465declare export function original<S>(value: S): ?S6667declare export function isDraft(value: any): boolean6869/**70 * Creates a mutable draft from an (immutable) object / array. 71 * The draft can be modified until `finishDraft` is called72 */73declare export function createDraft<T>(base: T): T7475/**76 * Given a draft that was created using `createDraft`, 77 * finalizes the draft into a new immutable object.78 * Optionally a patch-listener can be provided to gather the patches that are needed to construct the object.79 */80declare export function finishDraft<T>(base: T, listener?: PatchListener): Tfix: added flow typings for new API's introduced in v6. Fixes #570Michel Weststratebefore adoption0ddddfc
lines 81–85why, one step back8182declare export function enableES5(): void83declare export function enableMapSet(): void84declare export function enablePatches(): void85declare export function enableAllPlugins(): void