index.js.flow
This file
Path
src/types/index.js.flow
113 lines · 4.3 KiB
Last changed by
docs: Merge branch 'pvcresin-patch-1'Michel Weststratebefore adoptioncabcd3d
History of this fileTake it
fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 1–3why, one step back1// @flow23export interface Patch {Immer 7Michel Weststratebefore adoption467ea5d
lines 4–6why, one step back4 op: "replace" | "remove" | "add";5 path: (string | number)[];6 value?: any;fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 7–10why, one step back7}89export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void10fix: Flow: Add tests for Map and Set and fix base typeMichel Weststratebefore adoption9022672
line 11why, one step back11type Base = {...} | Array<any>fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
line 12why, one step back12interface IProduce {Immer 7Michel Weststratebefore adoption467ea5d
lines 13–30why, one step back13 /**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 */26 <S: Base>(27 currentState: S,28 recipe: (draftState: S) => S | void,29 patchListener?: PatchListener30 ): S;docs: Merge branch 'pvcresin-patch-1'Michel Weststratebefore adoptioncabcd3d
line 31why, one step back31 // curried invocations with initial stateImmer 7Michel Weststratebefore adoption467ea5d
lines 32–35why, 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,34 initialState: S35 ): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => S;docs: Merge branch 'pvcresin-patch-1'Michel Weststratebefore adoptioncabcd3d
line 36why, one step back36 // curried invocations without initial stateImmer 7Michel Weststratebefore adoption467ea5d
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–41why, one step back40}41fix(flow): added types for produceWithPatchesMichel Weststratebefore adoptionb355838
lines 42–52why, one step back42interface IProduceWithPatches {43 /**44 * Like `produce`, but instead of just returning the new state,45 * a tuple is returned with [nextState, patches, inversePatches]46 *47 * Like produce, this function supports currying48 */49 <S: Base>(50 currentState: S,51 recipe: (draftState: S) => S | void52 ): [S, Patch[], Patch[]];docs: Merge branch 'pvcresin-patch-1'Michel Weststratebefore adoptioncabcd3d
line 53why, one step back53 // curried invocations with initial statefix(flow): added types for produceWithPatchesMichel Weststratebefore adoptionb355838
lines 54–57why, one step back54 <S: Base, A = void, B = void, C = void>(55 recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void,56 initialState: S57 ): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];docs: Merge branch 'pvcresin-patch-1'Michel Weststratebefore adoptioncabcd3d
line 58why, one step back58 // curried invocations without initial statefix(flow): added types for produceWithPatchesMichel Weststratebefore adoptionb355838
lines 59–63why, one step back59 <S: Base, A = void, B = void, C = void>(60 recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void61 ): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];62}63fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 64–65why, one step back64declare export var produce: IProduce65declare export default IProducefix(flow): added types for produceWithPatchesMichel Weststratebefore adoptionb355838
lines 66–67why, one step back6667declare export var produceWithPatches: IProduceWithPatchesfix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 68–88why, one step back6869declare export var nothing: typeof undefined7071declare export var immerable: Symbol7273/**74 * Automatically freezes any state trees generated by immer.75 * This protects against accidental modifications of the state tree outside of an immer function.76 * This comes with a performance impact, so it is recommended to disable this option in production.77 * By default it is turned on during local development, and turned off in production.78 */79declare export function setAutoFreeze(autoFreeze: boolean): void8081/**82 * Manually override whether proxies should be used.83 * By default done by using feature detection84 */85declare export function setUseProxies(useProxies: boolean): void8687declare export function applyPatches<S>(state: S, patches: Patch[]): S88Immer 7Michel Weststratebefore adoption467ea5d
line 89why, one step back89declare export function original<S>(value: S): Sfix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
line 90why, one step back90Immer 7Michel Weststratebefore adoption467ea5d
lines 91–92why, one step back91declare export function current<S>(value: S): S92fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 93–95why, one step back93declare export function isDraft(value: any): boolean9495/**Immer 7Michel Weststratebefore adoption467ea5d
line 96why, one step back96 * Creates a mutable draft from an (immutable) object / array.fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 97–101why, one step back97 * The draft can be modified until `finishDraft` is called98 */99declare export function createDraft<T>(base: T): T100101/**Immer 7Michel Weststratebefore adoption467ea5d
line 102why, one step back102 * Given a draft that was created using `createDraft`,fix: Flow failed to find the Immer typingsMichel Weststratebefore adoptionc2ae050
lines 103–106why, one step back103 * finalizes the draft into a new immutable object.104 * Optionally a patch-listener can be provided to gather the patches that are needed to construct the object.105 */106declare export function finishDraft<T>(base: T, listener?: PatchListener): Tfix: added flow typings for new API's introduced in v6. Fixes #570Michel Weststratebefore adoption0ddddfc
lines 107–111why, one step back107108declare export function enableES5(): void109declare export function enableMapSet(): void110declare export function enablePatches(): void111declare export function enableAllPlugins(): voidfeature: Always freeze by default (#702)Michel Weststratebefore adoptiona406c8f
lines 112–113why, one step back112113declare export function freeze<T>(obj: T, freeze?: boolean): T