fix: Flow failed to find the Immer typings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by GitHub · parents ae5a13e, 6247c03 · Browse files · 3 files·+108 added−108 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+108 added−108 removed
- other:+108 added−108 removed
Provenance
- Commit
c2ae050- Tree
e951d1b- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
ae5a13e- Parent 2
6247c03
3 files changed+108 added−108 removed
deleted:src/types/immer.js.flow-107 removed
1-// @flow2-3-export interface Patch {4- op: "replace" | "remove" | "add",5- path: (string|number)[],6- value?: any7-}8-9-export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void10-11-interface 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-}68-69-declare export var produce: IProduce70-declare export default IProduce71-72-declare export var nothing: typeof undefined73-74-declare export var immerable: Symbol75-76-/**77- * Automatically freezes any state trees generated by immer.78- * This protects against accidental modifications of the state tree outside of an immer function.79- * This comes with a performance impact, so it is recommended to disable this option in production.80- * By default it is turned on during local development, and turned off in production.81- */82-declare export function setAutoFreeze(autoFreeze: boolean): void83-84-/**85- * Manually override whether proxies should be used.86- * By default done by using feature detection87- */88-declare export function setUseProxies(useProxies: boolean): void89-90-declare export function applyPatches<S>(state: S, patches: Patch[]): S91-92-declare export function original<S>(value: S): ?S93-94-declare export function isDraft(value: any): boolean95-96-/**97- * Creates a mutable draft from an (immutable) object / array. 98- * The draft can be modified until `finishDraft` is called99- */100-declare export function createDraft<T>(base: T): T101-102-/**103- * Given a draft that was created using `createDraft`, 104- * finalizes the draft into a new immutable object.105- * Optionally a patch-listener can be provided to gather the patches that are needed to construct the object.106- */107-declare export function finishDraft<T>(base: T, listener?: PatchListener): Tadded:src/types/index.js.flow+107 added
1+// @flow2+3+export interface Patch {4+ op: "replace" | "remove" | "add",5+ path: (string|number)[],6+ value?: any7+}8+9+export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void10+11+interface 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+}68+69+declare export var produce: IProduce70+declare export default IProduce71+72+declare export var nothing: typeof undefined73+74+declare export var immerable: Symbol75+76+/**77+ * Automatically freezes any state trees generated by immer.78+ * This protects against accidental modifications of the state tree outside of an immer function.79+ * This comes with a performance impact, so it is recommended to disable this option in production.80+ * By default it is turned on during local development, and turned off in production.81+ */82+declare export function setAutoFreeze(autoFreeze: boolean): void83+84+/**85+ * Manually override whether proxies should be used.86+ * By default done by using feature detection87+ */88+declare export function setUseProxies(useProxies: boolean): void89+90+declare export function applyPatches<S>(state: S, patches: Patch[]): S91+92+declare export function original<S>(value: S): ?S93+94+declare export function isDraft(value: any): boolean95+96+/**97+ * Creates a mutable draft from an (immutable) object / array. 98+ * The draft can be modified until `finishDraft` is called99+ */100+declare export function createDraft<T>(base: T): T101+102+/**103+ * Given a draft that was created using `createDraft`, 104+ * finalizes the draft into a new immutable object.105+ * Optionally a patch-listener can be provided to gather the patches that are needed to construct the object.106+ */107+declare export function finishDraft<T>(base: T, listener?: PatchListener): Tmodified:package.json+1 added-1 removed
31 unmodified lines3233343536363738394059 unmodified lines31 unmodified lines "watch": "jest --watch", "coverage": "jest --coverage", "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage", "build": "rimraf dist/ && tsdx build --name immer --format esm,cjs,umd && yarn build:flow", "build:flow": "cpx 'src/types/immer.js.flow' dist -v", "build:flow": "cpx 'src/types/index.js.flow' dist -v", "publish-docs": "cd website && GIT_USER=mweststrate USE_SSH=true yarn run publish-gh-pages", "start": "cd website && yarn start", "test:size": "yarn build && yarn import-size --report . produce enableES5 enableMapSet enablePatches enableAllPlugins", "test:sizequick": "tsdx build --name immer --format esm && yarn import-size . produce"59 unmodified lines