import * as react0 from "react"; import { ReactElement } from "react"; import { Draft, Patch, PatchListener } from "immer"; //#region src/Store.d.ts type TPullstateUpdateListener = () => void; interface IStoreInternalOptions { ssr: boolean; reactionCreators?: TReactionCreator[]; } type TUpdateFunction = (draft: Draft, original: S) => void; type TReactionFunction = (watched: T, draft: Draft, original: S, previousWatched: T) => void; type TRunReactionFunction = (forceRun?: boolean) => string[]; type TReactionCreator = (store: Store) => TRunReactionFunction; interface ICreateReactionOptions { runNow?: boolean; runNowWithSideEffects?: boolean; } type TStoreActionUpdate = (updater: TUpdateFunction | TUpdateFunction[], patchesCallback?: (patches: Patch[], inversePatches: Patch[]) => void) => void; type TStoreAction = (update: TStoreActionUpdate) => void; declare class Store { private updateListeners; private currentState; private readonly initialState; private readonly createInitialState; private internalOrdId; private batchState; private ssr; private reactions; private clientSubscriptions; private reactionCreators; private optimizedUpdateListeners; private optimizedUpdateListenerPaths; private optimizedListenerPropertyMap; _optListenerCount: number; _patchListeners: PatchListener[]; constructor(initialState: S | (() => S)); _setInternalOptions({ ssr, reactionCreators }: IStoreInternalOptions): void; _getReactionCreators(): TReactionCreator[]; _instantiateReactions(): void; _getInitialState(): S; _updateStateWithoutReaction(nextState: S): void; _updateState(nextState: S, updateKeyedPaths?: string[]): void; _addUpdateListener(listener: TPullstateUpdateListener): void; _removeUpdateListener(listener: TPullstateUpdateListener): void; _removeUpdateListenerOpt(ordKey: string): void; listenToPatches(patchListener: PatchListener): () => void; subscribe(watch: (state: S) => T, listener: (watched: T, allState: S, previousWatched: T) => void): () => void; createReaction(watch: (state: S) => T, reaction: TReactionFunction, { runNow, runNowWithSideEffects }?: ICreateReactionOptions): () => void; getRawState(): S; useState(): S; useState(getSubState: (state: S) => SS, deps?: ReadonlyArray): SS; useLocalCopyInitial(deps?: ReadonlyArray): Store; useLocalCopySnapshot(deps?: ReadonlyArray): Store; flushBatch(ignoreError?: boolean): void; update(updater: TUpdateFunction | TUpdateFunction[], patchesCallback?: (patches: Patch[], inversePatches: Patch[]) => void): void; replace(newState: S): void; replaceFromCurrent(replacer: (state: S) => S): void; applyPatches(patches: Patch[]): void; } declare function update(store: Store, updater: TUpdateFunction | TUpdateFunction[], patchesCallback?: (patches: Patch[], inversePatches: Patch[]) => void): void; //#endregion //#region src/useStoreState.d.ts declare function useStoreState(store: Store): S; declare function useStoreState(store: Store, getSubState: (state: S) => SS, deps?: ReadonlyArray): SS; //#endregion //#region src/InjectStoreState.d.ts interface IPropsInjectStoreState { store: Store; on?: (state: S) => SS; children: (output: SS) => ReactElement; } declare function InjectStoreState({ store, on, children }: IPropsInjectStoreState): ReactElement; //#endregion //#region src/async-types.d.ts type TPullstateAsyncUpdateListener = () => void; type TPullstateAsyncWatchResponse = [boolean, boolean, TAsyncActionResult, boolean, number]; type TPullstateAsyncBeckonResponse = [boolean, TAsyncActionResult, boolean]; type TPullstateAsyncRunResponse = Promise>; interface IPullstateAsyncResultState { [key: string]: TPullstateAsyncWatchResponse; } interface IPullstateAsyncActionOrdState { [key: string]: number; } declare enum EAsyncEndTags { THREW_ERROR = "THREW_ERROR", RETURNED_ERROR = "RETURNED_ERROR", UNFINISHED = "UNFINISHED", DORMANT = "DORMANT", } interface IAsyncActionResultBase { message: string; tags: (EAsyncEndTags | T)[]; } interface IAsyncActionResultPositive extends IAsyncActionResultBase { error: false; payload: R; errorPayload: null; } interface IAsyncActionResultNegative extends IAsyncActionResultBase { error: true; errorPayload: N; payload: null; } type TAsyncActionResult = IAsyncActionResultPositive | IAsyncActionResultNegative; type TPullstateAsyncShortCircuitHook = (inputs: { args: A; stores: S; }) => TAsyncActionResult | false; type TPullstateAsyncCacheBreakHook = (inputs: { args: A; result: TAsyncActionResult; stores: S; timeCached: number; }) => boolean; declare enum EPostActionContext { WATCH_HIT_CACHE = "WATCH_HIT_CACHE", BECKON_HIT_CACHE = "BECKON_HIT_CACHE", RUN_HIT_CACHE = "RUN_HIT_CACHE", READ_HIT_CACHE = "READ_HIT_CACHE", READ_RUN = "READ_RUN", SHORT_CIRCUIT = "SHORT_CIRCUIT", DIRECT_RUN = "DIRECT_RUN", BECKON_RUN = "BECKON_RUN", CACHE_UPDATE = "CACHE_UPDATE", } type TPullstateAsyncPostActionHook = (inputs: { args: A; result: TAsyncActionResult; stores: S; context: EPostActionContext; }) => void; interface IAsyncActionReadOptions { postActionEnabled?: boolean; cacheBreakEnabled?: boolean; key?: string; cacheBreak?: boolean | number | TPullstateAsyncCacheBreakHook; } interface IAsyncActionBeckonOptions extends IAsyncActionReadOptions { ssr?: boolean; holdPrevious?: boolean; dormant?: boolean; } interface IAsyncActionWatchOptions extends IAsyncActionBeckonOptions { initiate?: boolean; } interface IAsyncActionUseOptions extends IAsyncActionWatchOptions { onSuccess?: (result: R, args: A) => void; } interface IAsyncActionUseDeferOptions extends Omit, "key"> { key?: string; holdPrevious?: boolean; onSuccess?: (result: R, args: A) => void; clearOnSuccess?: boolean; } interface IAsyncActionRunOptions { treatAsUpdate?: boolean; ignoreShortCircuit?: boolean; respectCache?: boolean; key?: string; cacheBreak?: boolean | number | TPullstateAsyncCacheBreakHook; _asyncCache?: IPullstateAsyncCache; _stores?: S; _customContext?: any; } interface IAsyncActionGetCachedOptions { checkCacheBreak?: boolean; cacheBreak?: boolean | number | TPullstateAsyncCacheBreakHook; key?: string; } interface IGetCachedResponse { started: boolean; finished: boolean; result: TAsyncActionResult; updating: boolean; existed: boolean; cacheBreakable: boolean; timeCached: number; } interface IAsyncClearCacheOptions { notify?: boolean; } interface IAsyncActionSetOrClearCachedValueOptions extends IAsyncClearCacheOptions { key?: string; } interface IAsyncActionUpdateCachedOptions extends IAsyncActionSetOrClearCachedValueOptions { resetTimeCached?: boolean; runPostActionHook?: boolean; } type TAsyncActionUse = (args?: A, options?: IAsyncActionUseOptions) => TUseResponse; type TAsyncActionUseDefer = (options?: IAsyncActionUseDeferOptions) => TUseDeferResponse; type TAsyncActionBeckon = (args?: A, options?: IAsyncActionBeckonOptions) => TPullstateAsyncBeckonResponse; type TAsyncActionWatch = (args?: A, options?: IAsyncActionWatchOptions) => TPullstateAsyncWatchResponse; type TAsyncActionRun = (args?: A, options?: IAsyncActionRunOptions) => TPullstateAsyncRunResponse; type TAsyncActionClearCache = (args?: A, options?: IAsyncActionSetOrClearCachedValueOptions) => void; type TAsyncActionClearAllCache = (options?: IAsyncClearCacheOptions) => void; type TAsyncActionClearAllUnwatchedCache = (options?: IAsyncClearCacheOptions) => void; type TAsyncActionGetCached = (args?: A, options?: IAsyncActionGetCachedOptions) => IGetCachedResponse; type TAsyncActionSetCached = (args: A, result: TAsyncActionResult, options?: IAsyncActionSetOrClearCachedValueOptions) => void; type TAsyncActionSetCachedPayload = (args: A, payload: R, options?: IAsyncActionSetOrClearCachedValueOptions) => void; type TAsyncActionUpdateCached = (args: A, updater: TUpdateFunction, options?: IAsyncActionUpdateCachedOptions) => void; type TAsyncActionRead = (args?: A, options?: IAsyncActionReadOptions) => R; type TAsyncActionDelayedRun = (args: A, options: IAsyncActionRunOptions & { delay: number; clearOldRun?: boolean; immediateIfCached?: boolean; }) => () => void; interface IOCreateAsyncActionOutput { use: TAsyncActionUse; useDefer: TAsyncActionUseDefer; read: TAsyncActionRead; useBeckon: TAsyncActionBeckon; useWatch: TAsyncActionWatch; run: TAsyncActionRun; delayedRun: TAsyncActionDelayedRun; getCached: TAsyncActionGetCached; setCached: TAsyncActionSetCached; setCachedPayload: TAsyncActionSetCachedPayload; updateCached: TAsyncActionUpdateCached; clearCache: TAsyncActionClearCache; clearAllCache: TAsyncActionClearAllCache; clearAllUnwatchedCache: TAsyncActionClearAllUnwatchedCache; } interface IPullstateAsyncCache { results: IPullstateAsyncResultState; listeners: { [key: string]: { [watchId: string]: TPullstateAsyncUpdateListener; }; }; actions: { [key: string]: () => Promise>; }; actionOrd: IPullstateAsyncActionOrdState; } type TPullstateAsyncAction = (args: A, stores: S, customContext: any) => Promise>; interface ICreateAsyncActionOptions { forceContext?: boolean; shortCircuitHook?: TPullstateAsyncShortCircuitHook; cacheBreakHook?: TPullstateAsyncCacheBreakHook; postActionHook?: TPullstateAsyncPostActionHook; subsetKey?: (args: A) => any; actionId?: string | number; } interface IUseDebouncedExecutionOptions { validInput?: (args: A) => boolean; equality?: ((argsPrev: A, argsNew: A) => boolean) | any; executeOptions?: Omit, "key" | "cacheBreak">; watchLastValid?: boolean; } type TRunWithPayload = (func: (payload: R) => any) => any; interface IBaseObjResponseUse { execute: (runOptions?: IAsyncActionRunOptions) => TPullstateAsyncRunResponse; } interface IBaseObjResponseUseDefer { execute: (args?: A, runOptions?: Omit, "key" | "cacheBreak">) => TPullstateAsyncRunResponse; hasCached: (args?: A, options?: { successOnly?: boolean; } & Omit, "key">) => boolean; unwatchExecuted: () => void; useDebouncedExecution: (args: A, delay: number, options?: IUseDebouncedExecutionOptions) => void; args: A; key: string; } interface IBaseObjResponse { isLoading: boolean; isFinished: boolean; isUpdating: boolean; isStarted: boolean; clearCached: () => void; updateCached: (updater: TUpdateFunction, options?: IAsyncActionUpdateCachedOptions) => void; setCached: (result: TAsyncActionResult, options?: IAsyncActionSetOrClearCachedValueOptions) => void; setCachedPayload: (payload: R, options?: IAsyncActionSetOrClearCachedValueOptions) => void; endTags: (T | EAsyncEndTags)[]; renderPayload: TRunWithPayload; message: string; raw: TPullstateAsyncWatchResponse; } interface IBaseObjSuccessResponse extends IBaseObjResponse { payload: R; errorPayload: null; error: false; isSuccess: true; isFailure: false; } interface IBaseObjErrorResponse extends IBaseObjResponse { payload: null; errorPayload: N; error: true; isFailure: true; isSuccess: false; } type TUseResponse = (IBaseObjSuccessResponse | IBaseObjErrorResponse) & IBaseObjResponseUse; type TUseDeferResponse = (IBaseObjSuccessResponse | IBaseObjErrorResponse) & IBaseObjResponseUseDefer; //#endregion //#region src/PullstateCore.d.ts interface IPullstateAllStores { [storeName: string]: Store; } declare const PullstateContext: react0.Context | null>; declare const PullstateProvider: ({ instance, children }: { instance: PullstateInstance; children?: any; }) => JSX.Element; type TMultiStoreAction

, S extends IPullstateAllStores = (P extends PullstateSingleton ? ST : any)> = (update: TMultiStoreUpdateMap) => void; interface IPullstateSingletonOptions { asyncActions?: { defaultCachingSeconds?: number; }; } declare class PullstateSingleton { options: IPullstateSingletonOptions; constructor(allStores: S, options?: IPullstateSingletonOptions); instantiate({ hydrateSnapshot, ssr, customContext }?: { hydrateSnapshot?: IPullstateSnapshot; ssr?: boolean; customContext?: any; }): PullstateInstance; useStores(): S; useInstance(): PullstateInstance; createAsyncActionDirect(action: (args: A) => Promise, options?: ICreateAsyncActionOptions): IOCreateAsyncActionOutput; createAsyncAction(action: TPullstateAsyncAction, options?: ICreateAsyncActionOptions): IOCreateAsyncActionOutput; } type TMultiStoreUpdateMap = { [K in keyof S]: (updater: TUpdateFunction ? T : any>) => void }; interface IPullstateSnapshot { allState: { [storeName: string]: any; }; asyncResults: IPullstateAsyncResultState; asyncActionOrd: IPullstateAsyncActionOrdState; } interface IPullstateInstanceConsumable { stores: T; hasAsyncStateToResolve(): boolean; resolveAsyncState(): Promise; getPullstateSnapshot(): IPullstateSnapshot; hydrateFromSnapshot(snapshot: IPullstateSnapshot): void; runAsyncAction(asyncAction: IOCreateAsyncActionOutput, args?: A, runOptions?: Pick, "ignoreShortCircuit" | "respectCache">): TPullstateAsyncRunResponse; } declare class PullstateInstance implements IPullstateInstanceConsumable { private _ssr; private _customContext; private readonly _stores; _asyncCache: IPullstateAsyncCache; constructor(allStores: T, ssr: boolean, customContext: any); private getAllUnresolvedAsyncActions; instantiateReactions(): void; getPullstateSnapshot(): IPullstateSnapshot; resolveAsyncState(): Promise; hasAsyncStateToResolve(): boolean; get stores(): T; get customContext(): any; runAsyncAction(asyncAction: IOCreateAsyncActionOutput, args?: A, runOptions?: Pick, "ignoreShortCircuit" | "respectCache">): TPullstateAsyncRunResponse; hydrateFromSnapshot(snapshot: IPullstateSnapshot): void; } declare function createPullstateCore(allStores?: T, options?: IPullstateSingletonOptions): PullstateSingleton; declare function useStores(): T; declare function useInstance(): PullstateInstance; //#endregion //#region src/async.d.ts declare function successResult(payload?: R, tags?: (EAsyncEndTags | T)[], message?: string): IAsyncActionResultPositive; declare function errorResult(tags?: (EAsyncEndTags | T)[], message?: string, errorPayload?: N): IAsyncActionResultNegative; declare function createAsyncActionDirect(action: (args: A, stores: S, customContext: any) => Promise, options?: ICreateAsyncActionOptions): IOCreateAsyncActionOutput; declare function createAsyncAction(action: TPullstateAsyncAction, { forceContext, shortCircuitHook, cacheBreakHook, postActionHook, subsetKey, actionId }?: ICreateAsyncActionOptions): IOCreateAsyncActionOutput; //#endregion //#region src/InjectAsyncAction.d.ts declare enum EAsyncActionInjectType { WATCH = "watch", BECKON = "beckon", } interface IPropsInjectAsyncActionBase { action: IOCreateAsyncActionOutput; args?: A; } interface IPropsInjectAsyncActionBeckon extends IPropsInjectAsyncActionBase { type: EAsyncActionInjectType.BECKON; options?: IAsyncActionBeckonOptions; children: (response: TPullstateAsyncBeckonResponse) => ReactElement; } interface IPropsInjectAsyncActionWatch extends IPropsInjectAsyncActionBase { type: EAsyncActionInjectType.WATCH; children: (response: TPullstateAsyncWatchResponse) => ReactElement; options?: IAsyncActionWatchOptions; } type TInjectAsyncActionProps = IPropsInjectAsyncActionBeckon | IPropsInjectAsyncActionWatch; declare function InjectAsyncAction(props: TInjectAsyncActionProps): ReactElement; //#endregion //#region src/reduxDevtools.d.ts interface IORegisterInDevtoolsOptions { namespace?: string; } declare function registerInDevtools(stores: IPullstateAllStores, { namespace }?: IORegisterInDevtoolsOptions): void; //#endregion //#region src/useLocalStore.d.ts declare function useLocalStore(initialState: (() => S) | S, deps?: ReadonlyArray): Store; //#endregion //#region src/batch.d.ts interface IBatchState { uiBatchFunction: ((updates: () => void) => void); } declare function setupBatch({ uiBatchFunction }: IBatchState): void; declare function batch(runUpdates: () => void): void; //#endregion export { EAsyncActionInjectType, EAsyncEndTags, EPostActionContext, IAsyncActionBeckonOptions, IAsyncActionGetCachedOptions, IAsyncActionReadOptions, IAsyncActionResultNegative, IAsyncActionResultPositive, IAsyncActionRunOptions, IAsyncActionSetOrClearCachedValueOptions, IAsyncActionUpdateCachedOptions, IAsyncActionUseDeferOptions, IAsyncActionUseOptions, IAsyncActionWatchOptions, IAsyncClearCacheOptions, IBaseObjErrorResponse, IBaseObjResponse, IBaseObjResponseUse, IBaseObjResponseUseDefer, IBaseObjSuccessResponse, ICreateAsyncActionOptions, IGetCachedResponse, IOCreateAsyncActionOutput, IPullstateAllStores, IPullstateAsyncActionOrdState, IPullstateAsyncCache, IPullstateAsyncResultState, IPullstateInstanceConsumable, IUseDebouncedExecutionOptions, InjectAsyncAction, InjectStoreState, PullstateContext, PullstateProvider, type PullstateSingleton, Store, TAsyncActionBeckon, TAsyncActionClearAllCache, TAsyncActionClearAllUnwatchedCache, TAsyncActionClearCache, TAsyncActionDelayedRun, TAsyncActionGetCached, TAsyncActionRead, TAsyncActionResult, TAsyncActionRun, TAsyncActionSetCached, TAsyncActionSetCachedPayload, TAsyncActionUpdateCached, TAsyncActionUse, TAsyncActionUseDefer, TAsyncActionWatch, TInjectAsyncActionProps, TMultiStoreAction, TPullstateAsyncAction, TPullstateAsyncBeckonResponse, TPullstateAsyncCacheBreakHook, TPullstateAsyncPostActionHook, TPullstateAsyncRunResponse, TPullstateAsyncShortCircuitHook, TPullstateAsyncWatchResponse, TRunWithPayload, TStoreAction, TUpdateFunction, TUseDeferResponse, TUseResponse, batch, createAsyncAction, createAsyncActionDirect, createPullstateCore, errorResult, registerInDevtools, setupBatch, successResult, update, useInstance, useLocalStore, useStoreState, useStores };