diff --git a/package.json b/package.json index 2cae4a2..3844ff2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pullstate", - "version": "1.15.2", + "version": "1.15.3", "description": "Simple state stores using immer and React hooks", "main": "dist/index.js", "module": "dist/index.es.js", diff --git a/src/Store.ts b/src/Store.ts index 619b2af..75f09be 100644 --- a/src/Store.ts +++ b/src/Store.ts @@ -1,7 +1,7 @@ // @ts-ignore -import { applyPatches, enablePatches, Patch, PatchListener, produce, produceWithPatches } from "immer"; +import { applyPatches, Draft, enablePatches, Patch, PatchListener, produce, produceWithPatches } from "immer"; import { useStoreState } from "./useStoreState"; -import { DeepKeyOfArray, TAllPathsParameter } from "./useStoreStateOpt-types"; +import { DeepKeyOfArray } from "./useStoreStateOpt-types"; import isEqual from "fast-deep-equal/es6"; @@ -23,8 +23,8 @@ export interface IStoreInternalOptions { reactionCreators?: TReactionCreator[]; } -export type TUpdateFunction = (draft: S, original: S) => void; -type TPathReactionFunction = (paths: TAllPathsParameter, draft: S, original: S) => void; +export type TUpdateFunction = (draft: Draft, original: S) => void; +// type TPathReactionFunction = (paths: TAllPathsParameter, draft: S, original: S) => void; type TReactionFunction = (watched: T, draft: S, original: S, previousWatched: T) => void; type TRunReactionFunction = (forceRun?: boolean) => string[]; type TRunSubscriptionFunction = () => void; @@ -405,10 +405,10 @@ function runUpdates( func: boolean ): [S, Patch[], Patch[]] { return func - ? (produceWithPatches(currentState, (s: S) => (updater as TUpdateFunction)(s, currentState)) as any) + ? (produceWithPatches(currentState, (s: S) => (updater as TUpdateFunction)(s as Draft, currentState)) as any) : ((updater as TUpdateFunction[]).reduce( ([nextState, patches, inversePatches], currentValue) => { - const resp = produceWithPatches(nextState as any, (s: S) => currentValue(s, nextState)) as any; + const resp = produceWithPatches(nextState as any, (s: S) => currentValue(s as Draft, nextState)) as any; patches.push(...resp[1]); inversePatches.push(...resp[2]); return [resp[0], patches, inversePatches]; @@ -455,9 +455,9 @@ export function update( } else { nextState = produce(currentState as any, (s: S) => func - ? (updater as TUpdateFunction)(s, currentState) + ? (updater as TUpdateFunction)(s as Draft, currentState) : (updater as TUpdateFunction[]).reduce((previousValue, currentUpdater) => { - return produce(previousValue as any, (s: S) => currentUpdater(s, previousValue)) as any; + return produce(previousValue as any, (s: S) => currentUpdater(s as Draft, previousValue)) as any; }, currentState) ) as any; }