Skip to content
Myr

fix: revert .d.ts and .js.flow module names

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by aleclarson · committed by Alec Larson · parent 4b9b637 · Browse files · 4 files+280 added−280 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+280 added−280 removed

  • other:+280 added−280 removed

4 files+280 added−280 removed

added:src/immer.d.ts+188 added
1/** Object types that should never be mapped */2type AtomicObject =3 | Function4 | Map<any, any>5 | WeakMap<any, any>6 | Set<any>7 | WeakSet<any>8 | Promise<any>9 | Date10 | RegExp11 | Boolean12 | Number13 | String1415/** Use type inference to know when an array is finite */16type IsFinite<T extends any[]> = T extends never[]17 ? true18 : T extends ReadonlyArray<infer U>19 ? (U[] extends T ? false : true)20 : true2122export type DraftObject<T> = T extends object23 ? T extends AtomicObject24 ? T25 : {-readonly [P in keyof T]: Draft<T[P]>}26 : T2728export type DraftArray<T> = Array<29 T extends ReadonlyArray<any>30 ? {[P in keyof T]: Draft<T>}[keyof T]31 : DraftObject<T>32>3334export type DraftTuple<T extends any[]> = {35 [P in keyof T]: T[P] extends T[number] ? Draft<T[P]> : never36}3738export type Draft<T> = T extends any[]39 ? IsFinite<T> extends true40 ? DraftTuple<T>41 : DraftArray<T[number]>42 : T extends ReadonlyArray<any>43 ? DraftArray<T[number]>44 : T extends object45 ? DraftObject<T>46 : T4748export interface Patch {49 op: "replace" | "remove" | "add"50 path: (string | number)[]51 value?: any52}5354export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void5556export interface IProduce {57 /**58 * The `produce` function takes a value and a "recipe function" (whose59 * return value often depends on the base state). The recipe function is60 * free to mutate its first argument however it wants. All mutations are61 * only ever applied to a __copy__ of the base state.62 *63 * Pass only a function to create a "curried producer" which relieves you64 * from passing the recipe function every time.65 *66 * Only plain objects and arrays are made mutable. All other objects are67 * considered uncopyable.68 *69 * Note: This function is __bound__ to its `Immer` instance.70 *71 * @param {any} base - the initial state72 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified73 * @param {Function} patchListener - optional function that will be called with all the patches produced here74 * @returns {any} a new state, or the initial state if nothing was modified75 */76 <S = any, R = never>(77 currentState: S,78 recipe: (this: Draft<S>, draft: Draft<S>) => void | R,79 listener?: PatchListener80 ): R8182 /** Curried producer with an initial state */83 <S = any, R = never>(84 recipe: (this: Draft<S>, draft: Draft<S>) => void | R,85 defaultBase: S86 ): (base: S | undefined) => R8788 /** Curried producer with no initial state */89 <S = any, R = never, Args extends any[] = any[]>(90 recipe: (91 this: Draft<S>,92 draft: Draft<S>,93 ...extraArgs: Args94 ) => void | R95 ): (base: S, ...extraArgs: Args) => R96}9798export const produce: IProduce99export default produce100101/**102 * The sentinel value returned by producers to replace the draft with undefined.103 */104export const nothing: undefined105106/**107 * Pass true to automatically freeze all copies created by Immer.108 *109 * By default, auto-freezing is disabled in production.110 */111export function setAutoFreeze(autoFreeze: boolean): void112113/**114 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is115 * always faster than using ES5 proxies.116 *117 * By default, feature detection is used, so calling this is rarely necessary.118 */119export function setUseProxies(useProxies: boolean): void120121/**122 * Apply an array of Immer patches to the first argument.123 *124 * This function is a producer, which means copy-on-write is in effect.125 */126export function applyPatches<S>(base: S, patches: Patch[]): S127128export function original<T>(value: T): T | void129130export function isDraft(value: any): boolean131132export class Immer {133 constructor(config: {134 useProxies?: boolean135 autoFreeze?: boolean136 onAssign?: (state: ImmerState, prop: keyof any, value: any) => void137 onDelete?: (state: ImmerState, prop: keyof any) => void138 onCopy?: (state: ImmerState) => void139 })140 /**141 * The `produce` function takes a value and a "recipe function" (whose142 * return value often depends on the base state). The recipe function is143 * free to mutate its first argument however it wants. All mutations are144 * only ever applied to a __copy__ of the base state.145 *146 * Pass only a function to create a "curried producer" which relieves you147 * from passing the recipe function every time.148 *149 * Only plain objects and arrays are made mutable. All other objects are150 * considered uncopyable.151 *152 * Note: This function is __bound__ to its `Immer` instance.153 *154 * @param {any} base - the initial state155 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified156 * @param {Function} patchListener - optional function that will be called with all the patches produced here157 * @returns {any} a new state, or the initial state if nothing was modified158 */159 produce: IProduce160 /**161 * When true, `produce` will freeze the copies it creates.162 */163 readonly autoFreeze: boolean164 /**165 * When true, drafts are ES2015 proxies.166 */167 readonly useProxies: boolean168 /**169 * Pass true to automatically freeze all copies created by Immer.170 *171 * By default, auto-freezing is disabled in production.172 */173 setAutoFreeze(autoFreeze: boolean): void174 /**175 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is176 * always faster than using ES5 proxies.177 *178 * By default, feature detection is used, so calling this is rarely necessary.179 */180 setUseProxies(useProxies: boolean): void181}182183export interface ImmerState<T = any> {184 parent?: ImmerState185 base: T186 copy: T187 assigned: {[prop: string]: boolean}188}
added:src/immer.js.flow+92 added
1// @flow23export interface Patch {4 op: "replace" | "remove" | "add",5 path: (string|number)[],6 value?: any7}89export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void1011interface 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,27 recipe: (draftState: S) => S | void,28 patchListener?: PatchListener29 ): 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 IProduce7172declare export var nothing: typeof undefined7374/**75 * Automatically freezes any state trees generated by immer.76 * This protects against accidental modifications of the state tree outside of an immer function.77 * This comes with a performance impact, so it is recommended to disable this option in production.78 * By default it is turned on during local development, and turned off in production.79 */80declare export function setAutoFreeze(autoFreeze: boolean): void8182/**83 * Manually override whether proxies should be used.84 * By default done by using feature detection85 */86declare export function setUseProxies(useProxies: boolean): void8788declare export function applyPatches<S>(state: S, patches: Patch[]): S8990declare export function original<S>(value: S): ?S9192declare export function isDraft(value: any): boolean
deleted:src/index.d.ts-188 removed
1/** Object types that should never be mapped */2type AtomicObject =3 | Function4 | Map<any, any>5 | WeakMap<any, any>6 | Set<any>7 | WeakSet<any>8 | Promise<any>9 | Date10 | RegExp11 | Boolean12 | Number13 | String1415/** Use type inference to know when an array is finite */16type IsFinite<T extends any[]> = T extends never[]17 ? true18 : T extends ReadonlyArray<infer U>19 ? (U[] extends T ? false : true)20 : true2122export type DraftObject<T> = T extends object23 ? T extends AtomicObject24 ? T25 : {-readonly [P in keyof T]: Draft<T[P]>}26 : T2728export type DraftArray<T> = Array<29 T extends ReadonlyArray<any>30 ? {[P in keyof T]: Draft<T>}[keyof T]31 : DraftObject<T>32>3334export type DraftTuple<T extends any[]> = {35 [P in keyof T]: T[P] extends T[number] ? Draft<T[P]> : never36}3738export type Draft<T> = T extends any[]39 ? IsFinite<T> extends true40 ? DraftTuple<T>41 : DraftArray<T[number]>42 : T extends ReadonlyArray<any>43 ? DraftArray<T[number]>44 : T extends object45 ? DraftObject<T>46 : T4748export interface Patch {49 op: "replace" | "remove" | "add"50 path: (string | number)[]51 value?: any52}5354export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void5556export interface IProduce {57 /**58 * The `produce` function takes a value and a "recipe function" (whose59 * return value often depends on the base state). The recipe function is60 * free to mutate its first argument however it wants. All mutations are61 * only ever applied to a __copy__ of the base state.62 *63 * Pass only a function to create a "curried producer" which relieves you64 * from passing the recipe function every time.65 *66 * Only plain objects and arrays are made mutable. All other objects are67 * considered uncopyable.68 *69 * Note: This function is __bound__ to its `Immer` instance.70 *71 * @param {any} base - the initial state72 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified73 * @param {Function} patchListener - optional function that will be called with all the patches produced here74 * @returns {any} a new state, or the initial state if nothing was modified75 */76 <S = any, R = never>(77 currentState: S,78 recipe: (this: Draft<S>, draft: Draft<S>) => void | R,79 listener?: PatchListener80 ): R8182 /** Curried producer with an initial state */83 <S = any, R = never>(84 recipe: (this: Draft<S>, draft: Draft<S>) => void | R,85 defaultBase: S86 ): (base: S | undefined) => R8788 /** Curried producer with no initial state */89 <S = any, R = never, Args extends any[] = any[]>(90 recipe: (91 this: Draft<S>,92 draft: Draft<S>,93 ...extraArgs: Args94 ) => void | R95 ): (base: S, ...extraArgs: Args) => R96}9798export const produce: IProduce99export default produce100101/**102 * The sentinel value returned by producers to replace the draft with undefined.103 */104export const nothing: undefined105106/**107 * Pass true to automatically freeze all copies created by Immer.108 *109 * By default, auto-freezing is disabled in production.110 */111export function setAutoFreeze(autoFreeze: boolean): void112113/**114 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is115 * always faster than using ES5 proxies.116 *117 * By default, feature detection is used, so calling this is rarely necessary.118 */119export function setUseProxies(useProxies: boolean): void120121/**122 * Apply an array of Immer patches to the first argument.123 *124 * This function is a producer, which means copy-on-write is in effect.125 */126export function applyPatches<S>(base: S, patches: Patch[]): S127128export function original<T>(value: T): T | void129130export function isDraft(value: any): boolean131132export class Immer {133 constructor(config: {134 useProxies?: boolean135 autoFreeze?: boolean136 onAssign?: (state: ImmerState, prop: keyof any, value: any) => void137 onDelete?: (state: ImmerState, prop: keyof any) => void138 onCopy?: (state: ImmerState) => void139 })140 /**141 * The `produce` function takes a value and a "recipe function" (whose142 * return value often depends on the base state). The recipe function is143 * free to mutate its first argument however it wants. All mutations are144 * only ever applied to a __copy__ of the base state.145 *146 * Pass only a function to create a "curried producer" which relieves you147 * from passing the recipe function every time.148 *149 * Only plain objects and arrays are made mutable. All other objects are150 * considered uncopyable.151 *152 * Note: This function is __bound__ to its `Immer` instance.153 *154 * @param {any} base - the initial state155 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified156 * @param {Function} patchListener - optional function that will be called with all the patches produced here157 * @returns {any} a new state, or the initial state if nothing was modified158 */159 produce: IProduce160 /**161 * When true, `produce` will freeze the copies it creates.162 */163 readonly autoFreeze: boolean164 /**165 * When true, drafts are ES2015 proxies.166 */167 readonly useProxies: boolean168 /**169 * Pass true to automatically freeze all copies created by Immer.170 *171 * By default, auto-freezing is disabled in production.172 */173 setAutoFreeze(autoFreeze: boolean): void174 /**175 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is176 * always faster than using ES5 proxies.177 *178 * By default, feature detection is used, so calling this is rarely necessary.179 */180 setUseProxies(useProxies: boolean): void181}182183export interface ImmerState<T = any> {184 parent?: ImmerState185 base: T186 copy: T187 assigned: {[prop: string]: boolean}188}
deleted:src/index.js.flow-92 removed
1// @flow23export interface Patch {4 op: "replace" | "remove" | "add",5 path: (string|number)[],6 value?: any7}89export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void1011interface 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,27 recipe: (draftState: S) => S | void,28 patchListener?: PatchListener29 ): 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 IProduce7172declare export var nothing: typeof undefined7374/**75 * Automatically freezes any state trees generated by immer.76 * This protects against accidental modifications of the state tree outside of an immer function.77 * This comes with a performance impact, so it is recommended to disable this option in production.78 * By default it is turned on during local development, and turned off in production.79 */80declare export function setAutoFreeze(autoFreeze: boolean): void8182/**83 * Manually override whether proxies should be used.84 * By default done by using feature detection85 */86declare export function setUseProxies(useProxies: boolean): void8788declare export function applyPatches<S>(state: S, patches: Patch[]): S8990declare export function original<S>(value: S): ?S9192declare export function isDraft(value: any): boolean