state-decorator 7.3.0 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/v6.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { GlobalConfig, ParallelActionError, EffectError } from './impl';
2
- import type { DecoratedActions, StoreActions, AsyncAction, SyncAction, SimpleSyncAction, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, StoreOptions as StoreOptionsBase, AsyncActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, ContextState, Middleware, AbortActionCallback, MiddlewareFactory, LoadingProps, ErrorProps, LoadingMapProps, StoreConfig } from './types';
3
- import { setGlobalConfig, IsLoadingFunc, StoreApi, StateListenerContext, ConflictPolicy } from './index';
4
- export type { StateListenerContext, StoreApi, DecoratedActions, StoreActions, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, AsyncActionPromise as AsynchActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, SyncAction, AsyncAction, SimpleSyncAction, ContextState, GlobalConfig, Middleware, LoadingProps, AbortActionCallback, ErrorProps, LoadingMapProps, StoreConfig, IsLoadingFunc, };
5
- export { EffectError, ParallelActionError, ConflictPolicy, setGlobalConfig };
6
- export type StoreOptions<S, A, P = {}, DS = {}, FxRes = S> = StoreOptionsBase<S, A, P, DS, FxRes>;
7
- export type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
8
- /**
9
- * Creates and manages a local store.
10
- * The component will be refreshed for every change in the store.
11
- * Store will NOT be destroyed when component is unmouted.
12
- *
13
- * @param getInitialState Function to compute initial state from props.
14
- * @param actionImpl Actions implementation.
15
- * @param props Owner component props to update state or react on prop changes
16
- * @param options The store options.
17
- * @param refreshOnUpdate Whether refresh the component if store state changes.
18
- * @returns The state, actions and isLoading function.
19
- */
20
- export default function useLocalStoreV6<S, A extends DecoratedActions, P, DS = {}>(getInitialState: (p: P) => S, actionImpl: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, middlewares?: MiddlewareFactory<S, A, P>[], refreshOnUpdate?: boolean): StoreApi<S, A, P, DS>;
21
- export declare const useLocalStore: typeof useLocalStoreV6;
1
+ import { GlobalConfig, ParallelActionError, EffectError } from './impl';
2
+ import type { DecoratedActions, StoreActions, AsyncAction, SyncAction, SimpleSyncAction, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, StoreOptions as StoreOptionsBase, AsyncActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, ContextState, Middleware, AbortActionCallback, MiddlewareFactory, LoadingProps, ErrorProps, LoadingMapProps, StoreConfig } from './types';
3
+ import { setGlobalConfig, IsLoadingFunc, StoreApi, StateListenerContext, ConflictPolicy } from './index';
4
+ export type { StateListenerContext, StoreApi, DecoratedActions, StoreActions, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, AsyncActionPromise as AsynchActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, SyncAction, AsyncAction, SimpleSyncAction, ContextState, GlobalConfig, Middleware, LoadingProps, AbortActionCallback, ErrorProps, LoadingMapProps, StoreConfig, IsLoadingFunc, };
5
+ export { EffectError, ParallelActionError, ConflictPolicy, setGlobalConfig };
6
+ export type StoreOptions<S, A, P = {}, DS = {}, FxRes = S> = StoreOptionsBase<S, A, P, DS, FxRes>;
7
+ export type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
8
+ /**
9
+ * Creates and manages a local store.
10
+ * The component will be refreshed for every change in the store.
11
+ * Store will NOT be destroyed when component is unmouted.
12
+ *
13
+ * @param getInitialState Function to compute initial state from props.
14
+ * @param actionImpl Actions implementation.
15
+ * @param props Owner component props to update state or react on prop changes
16
+ * @param options The store options.
17
+ * @param refreshOnUpdate Whether refresh the component if store state changes.
18
+ * @returns The state, actions and isLoading function.
19
+ */
20
+ export default function useLocalStoreV6<S, A extends DecoratedActions, P, DS = {}>(getInitialState: (p: P) => S, actionImpl: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, middlewares?: MiddlewareFactory<S, A, P>[], refreshOnUpdate?: boolean): StoreApi<S, A, P, DS>;
21
+ export declare const useLocalStore: typeof useLocalStoreV6;
package/graph.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export default class Graph {
2
- private keys;
3
- private adj;
4
- constructor(keys: string[]);
5
- private isCyclicUtil;
6
- setEdges(sou: string, dest: string[]): void;
7
- isCyclic(): boolean;
8
- }
1
+ export default class Graph {
2
+ private keys;
3
+ private adj;
4
+ constructor(keys: string[]);
5
+ private isCyclicUtil;
6
+ setEdges(sou: string, dest: string[]): void;
7
+ isCyclic(): boolean;
8
+ }
package/helpers.d.ts CHANGED
@@ -1,67 +1,67 @@
1
- /**
2
- * Effect function that sets the first action argument to the specified prop.
3
- * if dirtyProp is set
4
- */
5
- export declare function setArgIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
6
- s: S;
7
- args: [S[K]];
8
- }) => Partial<S>;
9
- /**
10
- * Effect function that sets <code>true</code> in the specified prop.
11
- */
12
- export declare function setTrueIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
13
- s: S;
14
- }) => Partial<S>;
15
- /**
16
- * Effect function that sets <code>false</code> in the specified prop.
17
- */
18
- export declare function setFalseIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
19
- s: S;
20
- }) => Partial<S>;
21
- /**
22
- * Effect function that sets toggles the boolean value of the specified prop.
23
- */
24
- export declare function toggleProp<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
25
- s: S;
26
- }) => Partial<S>;
27
- /**
28
- * Effect function that sets the update the specifed prop as an array using first action argument as index
29
- * and second as value to set.
30
- */
31
- export declare function setArgsInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
32
- s: S;
33
- args: [string, T];
34
- }) => Partial<S>;
35
- /**
36
- * Effect function that sets the update the specifed prop as an array using first action argument as index
37
- * and second as value to set.
38
- */
39
- export declare function setArgsInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
40
- s: S;
41
- args: [number, T];
42
- }) => Partial<S>;
43
- /**
44
- * Effect function that sets the asynchronous action result to the specified prop.
45
- */
46
- export declare function setResIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
47
- s: S;
48
- res: S[K];
49
- }) => Partial<S>;
50
- /**
51
- * Effect function that sets the update the specifed prop as an array using first action argument as index
52
- * and second as value to set.
53
- */
54
- export declare function setResInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
55
- s: S;
56
- args: [number];
57
- res: T;
58
- }) => Partial<S>;
59
- /**
60
- * Effect function that sets the update the specifed prop as an array using first action argument as index
61
- * and second as value to set.
62
- */
63
- export declare function setResInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
64
- s: S;
65
- args: [string];
66
- res: T;
67
- }) => Partial<S>;
1
+ /**
2
+ * Effect function that sets the first action argument to the specified prop.
3
+ * if dirtyProp is set
4
+ */
5
+ export declare function setArgIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
6
+ s: S;
7
+ args: [S[K]];
8
+ }) => Partial<S>;
9
+ /**
10
+ * Effect function that sets <code>true</code> in the specified prop.
11
+ */
12
+ export declare function setTrueIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
13
+ s: S;
14
+ }) => Partial<S>;
15
+ /**
16
+ * Effect function that sets <code>false</code> in the specified prop.
17
+ */
18
+ export declare function setFalseIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
19
+ s: S;
20
+ }) => Partial<S>;
21
+ /**
22
+ * Effect function that sets toggles the boolean value of the specified prop.
23
+ */
24
+ export declare function toggleProp<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
25
+ s: S;
26
+ }) => Partial<S>;
27
+ /**
28
+ * Effect function that sets the update the specifed prop as an array using first action argument as index
29
+ * and second as value to set.
30
+ */
31
+ export declare function setArgsInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
32
+ s: S;
33
+ args: [string, T];
34
+ }) => Partial<S>;
35
+ /**
36
+ * Effect function that sets the update the specifed prop as an array using first action argument as index
37
+ * and second as value to set.
38
+ */
39
+ export declare function setArgsInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
40
+ s: S;
41
+ args: [number, T];
42
+ }) => Partial<S>;
43
+ /**
44
+ * Effect function that sets the asynchronous action result to the specified prop.
45
+ */
46
+ export declare function setResIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
47
+ s: S;
48
+ res: S[K];
49
+ }) => Partial<S>;
50
+ /**
51
+ * Effect function that sets the update the specifed prop as an array using first action argument as index
52
+ * and second as value to set.
53
+ */
54
+ export declare function setResInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
55
+ s: S;
56
+ args: [number];
57
+ res: T;
58
+ }) => Partial<S>;
59
+ /**
60
+ * Effect function that sets the update the specifed prop as an array using first action argument as index
61
+ * and second as value to set.
62
+ */
63
+ export declare function setResInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
64
+ s: S;
65
+ args: [string];
66
+ res: T;
67
+ }) => Partial<S>;
package/impl.d.ts CHANGED
@@ -1,208 +1,208 @@
1
- import { AsyncAction, SimpleSyncAction, SyncAction, StoreAction, AsyncActionPromise, AsyncActionPromiseGet, PromiseProvider, DecoratedActions, InternalLoadingMap, StoreOptions, InvocationContextActions, OnMountInvocationContext, OnPropsChangeEffectsContext, ContextState, Middleware, MiddlewareFactory, ContextWithDerived, PromiseIdErrorMap, ErrorMap, ErrorParallelMap, OnUnMountInvocationContext, AbortedActions, ClearErrorFunc, StoreConfig, StoreConfigFunc } from './types';
2
- export type SetStateFunc<S, A> = (newState: S, newLoadingMap: InternalLoadingMap<A>, actionName: keyof A | 'onPropsChange', actionType: 'preEffects' | 'effects' | 'errorEffects' | null, // FIXME
3
- isAsync: boolean, actionCtx: any, propsChanged: boolean, isInit?: boolean) => void;
4
- /** @internal */
5
- export type PromiseMap<A> = {
6
- [name in keyof A]?: {
7
- [promiseId: string]: {
8
- promise: Promise<any>;
9
- refArgs: any[];
10
- abortController: AbortController;
11
- };
12
- };
13
- };
14
- /** @internal */
15
- export type FutureActions = {
16
- args: any[];
17
- resolve: (...args: any[]) => void;
18
- reject: (...args: any[]) => void;
19
- timestamp?: number;
20
- };
21
- /** @internal */
22
- export type ConflictActionsMap<A> = {
23
- [name in keyof A]?: FutureActions[];
24
- };
25
- /** @internal */
26
- export type AsyncActionExecContext<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P> = {
27
- actionName: keyof A;
28
- action: AsyncActionPromise<S, F, A, P, DS>;
29
- stateRef: Ref<S>;
30
- derivedStateRef: Ref<DerivedState<DS>>;
31
- propsRef: Ref<P>;
32
- loadingParallelMapRef: Ref<InternalLoadingMap<A>>;
33
- errorMapRef: Ref<ErrorParallelMap<A>>;
34
- promisesRef: Ref<PromiseMap<A>>;
35
- conflictActionsRef: Ref<ConflictActionsMap<A>>;
36
- actionsRef: Ref<A>;
37
- initializedRef: Ref<boolean>;
38
- options: StoreOptions<S, A, P, any>;
39
- setState: SetStateFunc<S, A>;
40
- clearError: ClearErrorFunc<A>;
41
- };
42
- /** @internal */
43
- export type TimeoutMap<A> = {
44
- [name in keyof A]?: any;
45
- };
46
- export type NotifyFunc = (msg: string) => void;
47
- export type CloneFunction = <C>(obj: C) => C;
48
- export type ComparatorFunction = <C>(obj1: C, Obj2: C) => boolean;
49
- export type RetryOnErrorFunction = (error: any) => boolean;
50
- export type AsyncErrorHandler = (error: any, isHandled: boolean, state: any, props: any, actionName: string, args: any[]) => void;
51
- type DerivedStateMap<DS> = {
52
- [name in keyof DS]?: any[];
53
- };
54
- /** @internal */
55
- export type DerivedState<DS> = {
56
- state: DS;
57
- deps: DerivedStateMap<DS>;
58
- };
59
- export declare class EffectError extends Error {
60
- /**
61
- * The wrapped error
62
- */
63
- source: any;
64
- /**
65
- * If effects error occurred while processed an error, the initial error.
66
- */
67
- initialError: Error;
68
- constructor(source: any, initialError?: Error);
69
- }
70
- /**
71
- * Global configuration, shared with all stores.
72
- */
73
- export type GlobalConfig = {
74
- /**
75
- * Clone function.
76
- * Used to clone state and props when managing optimistic reducer and conflicting actions.
77
- * Default implementation is a very basic algorithm using JSON.stringify. To clone complex stats,
78
- * use a custom implementation like lodash/cloneDeep.
79
- * @default JSON.stringify
80
- */
81
- clone: CloneFunction;
82
- /**
83
- * Compare to objets and returns if they are equal.
84
- * Used to comparent previous and current state slice.
85
- * @default shallow
86
- */
87
- comparator: ComparatorFunction;
88
- /**
89
- * Global callback function to handle asychronous actions rejected promise.
90
- */
91
- asyncErrorHandler: AsyncErrorHandler;
92
- /**
93
- * Tests if the error will trigger a retry of the action or will fail directly.
94
- * Default implementation is returning true for TypeError instances only.
95
- * @see AsynchActionBase#retryCount
96
- */
97
- retryOnErrorFunction: RetryOnErrorFunction;
98
- /**
99
- * First retry timeout. Every retry will wait x
100
- */
101
- autoRetryTimeout: number;
102
- /**
103
- * Number of retries in case of error (failed to fetch).
104
- * If <code>0</code>, retry is globally disabled.
105
- */
106
- autoRetryCount: number;
107
- /**
108
- * Global notification function that will called when an asynchronous action succeeded,
109
- * if and only if, an error message is specified for this action using
110
- * <code>getErrorMessage</code>.
111
- * If another function is set in the options, the function from the options will be used.
112
- */
113
- notifySuccess: NotifyFunc;
114
- /**
115
- * Global notification function that will called when an asynchronous action fails,
116
- * if and only if, an error message is specified for this action using
117
- * <code>getErrorMessage</code>.
118
- * If another function is set in the options, the function from the options will be used.
119
- */
120
- notifyError: NotifyFunc;
121
- /**
122
- * Global notification function that will injected in onDone and onFail of an asynchronous actions and onActionDone of a synchronous function,
123
- * If another function is set in the options, the function from the options will be used.
124
- */
125
- notifyWarning: NotifyFunc;
126
- /**
127
- * A default error message provider.
128
- * Used to return generic messages on generic HTTP errors
129
- */
130
- getErrorMessage: (error: Error) => string;
131
- /**
132
- * Default middlewares. Store middleware array will be concatenated with this one.
133
- * By default contains only the optimistic middleware.
134
- */
135
- defaultMiddlewares: MiddlewareFactory<any, any, any>[];
136
- };
137
- /** @internal */
138
- export declare const globalConfig: GlobalConfig;
139
- export declare function setGlobalConfig(overrideConfig: Partial<GlobalConfig>): void;
140
- /**
141
- * Type guard function to test if an action is a asynchronous action.
142
- */
143
- export declare function isAsyncAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncAction<S, F, A, P, DS, FxRes>;
144
- /**
145
- * Type guard function to test if an action is a synchronous action.
146
- */
147
- export declare function isSimpleSyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is SimpleSyncAction<S, F, P, DS, FxRes>;
148
- /**
149
- * Type guard function to test if an action is a synchronous action.
150
- */
151
- export declare function isSyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is SyncAction<S, F, A, P, DS, FxRes>;
152
- export declare function isAsyncGetPromiseAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncActionPromise<S, F, A, P, DS, FxRes>;
153
- export declare function isAsyncGetPromiseGetAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
154
- /** @internal */
155
- export declare function computeAsyncActionInput<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: AsyncAction<S, F, A, P, DS, FxRes>): AsyncActionPromise<S, F, A, P, DS, FxRes>;
156
- /** @internal */
157
- export declare function buildLoadingMap<A>(source: InternalLoadingMap<A>, actionName: keyof A, promiseId: string, loading: boolean): InternalLoadingMap<A>;
158
- /** @internal */
159
- export declare function updateErrorMap<A>(source: ErrorParallelMap<A>, actionName: keyof A, promiseId: string, error: Error): ErrorParallelMap<A>;
160
- export declare class ParallelActionError extends Error {
161
- promiseIds: PromiseIdErrorMap;
162
- constructor(promiseIds: PromiseIdErrorMap);
163
- }
164
- export declare function buildErrorMap<A>(map: ErrorParallelMap<A>): ErrorMap<A>;
165
- /** @internal */
166
- export declare function retryPromiseDecorator<S, DS, F extends (...args: any[]) => Promise<any>, A, P>(promiseProvider: PromiseProvider<S, DS, F, A, P>, maxCalls?: number, delay?: number, isRetryError?: (e: Error) => boolean): PromiseProvider<S, DS, F, A, P>;
167
- export type Ref<P> = {
168
- current: P;
169
- };
170
- /** @internal */
171
- export declare function createRef<U>(init?: U): Ref<U>;
172
- /** @internal */
173
- export declare function buildInvocationContextBase<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>): ContextWithDerived<S, DS, P>;
174
- /** @internal */
175
- export declare function buildOnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>): OnMountInvocationContext<S, A, P>;
176
- /** @internal */
177
- export declare function buildOnUnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, abortedActions: AbortedActions<A>): OnUnMountInvocationContext<S, A, P>;
178
- /** @internal */
179
- export declare function buildOnPropChangeEffects<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, indices: number[], index: number, isInit: boolean, getInitialState: (p: P) => S): OnPropsChangeEffectsContext<S, DS, P>;
180
- /** @internal */
181
- export declare function addStateToContext<T, S>(ctx: T, stateRef: Ref<S>): T & ContextState<S>;
182
- /** @internal */
183
- export declare function addContextActions<T, A>(ctx: T, actionsRef: Ref<A>): T & InvocationContextActions<A>;
184
- /** @internal */
185
- export declare function isFuncConfig<S, A extends DecoratedActions, P = {}, DS = {}>(config: StoreConfig<S, A, P, DS>): config is StoreConfigFunc<S, A, P, DS>;
186
- /** @internal */
187
- export declare function decorateSimpleSyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(actionName: keyof A, action: SimpleSyncAction<S, F, P, DS>, stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, initializedRef: Ref<boolean>, options: StoreOptions<S, A, P, DS>, setState: SetStateFunc<S, A>): (...args: Parameters<F>) => void;
188
- /** @internal */
189
- export declare function decorateSyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(actionName: keyof A, action: SyncAction<S, F, A, P, DS>, stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>, initializedRef: Ref<boolean>, timeoutMap: Ref<TimeoutMap<A>>, options: StoreOptions<S, A, P, any>, setState: SetStateFunc<S, A>, clearError: ClearErrorFunc<A>): (...args: Parameters<F>) => void;
190
- /** @internal */
191
- export declare function decorateAsyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(context: AsyncActionExecContext<S, DS, F, A, P>): (...args: Parameters<F>) => Promise<any>;
192
- /** @internal */
193
- export declare function isLoadingImpl<A, K extends keyof A>(loadingMap: InternalLoadingMap<A>, ...props: (K | [K, string])[]): boolean;
194
- export declare const DEFAULT_PROMISE_ID = "__def__";
195
- /** @internal */
196
- export declare function areSameArgs(args1: any[], args2: any[]): boolean;
197
- /** @internal */
198
- export declare function computeDerivedValues<S, A, P, DS>(s: Ref<S>, p: Ref<P>, derivedStateRef: Ref<DerivedState<DS>>, options: StoreOptions<S, A, P, DS>): boolean;
199
- /** @internal */
200
- export declare function fixDerivedDeps<S, A, P, DS>(options: StoreOptions<S, A, P, DS>): void;
201
- /** @internal */
202
- export declare function onPropChange<S, P, A, DS>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, oldProps: P, actionsRef: Ref<A>, options: StoreOptions<S, A, P, DS>, getInitialState: (p: P) => S, setState: SetStateFunc<S, A>, isInit: boolean, isDeferred: boolean): void;
203
- /** @internal */
204
- export declare function runMiddlewares<S, A extends DecoratedActions, P>(middlewares: Middleware<S, A, P>[], oldState: S, newState: S, loading: boolean, actionName: keyof A, actionType: 'preEffects' | 'effects' | 'errorEffects' | null, isAsync: boolean, actionCtx: any): {
205
- newState: S;
206
- newLoading: boolean;
207
- };
208
- export {};
1
+ import { AsyncAction, SimpleSyncAction, SyncAction, StoreAction, AsyncActionPromise, AsyncActionPromiseGet, PromiseProvider, DecoratedActions, InternalLoadingMap, StoreOptions, InvocationContextActions, OnMountInvocationContext, OnPropsChangeEffectsContext, ContextState, Middleware, MiddlewareFactory, ContextWithDerived, PromiseIdErrorMap, ErrorMap, ErrorParallelMap, OnUnMountInvocationContext, AbortedActions, ClearErrorFunc, StoreConfig, StoreConfigFunc } from './types';
2
+ export type SetStateFunc<S, A> = (newState: S, newLoadingMap: InternalLoadingMap<A>, actionName: keyof A | 'onPropsChange', actionType: 'preEffects' | 'effects' | 'errorEffects' | null, // FIXME
3
+ isAsync: boolean, actionCtx: any, propsChanged: boolean, isInit?: boolean) => void;
4
+ /** @internal */
5
+ export type PromiseMap<A> = {
6
+ [name in keyof A]?: {
7
+ [promiseId: string]: {
8
+ promise: Promise<any>;
9
+ refArgs: any[];
10
+ abortController: AbortController;
11
+ };
12
+ };
13
+ };
14
+ /** @internal */
15
+ export type FutureActions = {
16
+ args: any[];
17
+ resolve: (...args: any[]) => void;
18
+ reject: (...args: any[]) => void;
19
+ timestamp?: number;
20
+ };
21
+ /** @internal */
22
+ export type ConflictActionsMap<A> = {
23
+ [name in keyof A]?: FutureActions[];
24
+ };
25
+ /** @internal */
26
+ export type AsyncActionExecContext<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P> = {
27
+ actionName: keyof A;
28
+ action: AsyncActionPromise<S, F, A, P, DS>;
29
+ stateRef: Ref<S>;
30
+ derivedStateRef: Ref<DerivedState<DS>>;
31
+ propsRef: Ref<P>;
32
+ loadingParallelMapRef: Ref<InternalLoadingMap<A>>;
33
+ errorMapRef: Ref<ErrorParallelMap<A>>;
34
+ promisesRef: Ref<PromiseMap<A>>;
35
+ conflictActionsRef: Ref<ConflictActionsMap<A>>;
36
+ actionsRef: Ref<A>;
37
+ initializedRef: Ref<boolean>;
38
+ options: StoreOptions<S, A, P, any>;
39
+ setState: SetStateFunc<S, A>;
40
+ clearError: ClearErrorFunc<A>;
41
+ };
42
+ /** @internal */
43
+ export type TimeoutMap<A> = {
44
+ [name in keyof A]?: any;
45
+ };
46
+ export type NotifyFunc = (msg: string) => void;
47
+ export type CloneFunction = <C>(obj: C) => C;
48
+ export type ComparatorFunction = <C>(obj1: C, Obj2: C) => boolean;
49
+ export type RetryOnErrorFunction = (error: any) => boolean;
50
+ export type AsyncErrorHandler = (error: any, isHandled: boolean, state: any, props: any, actionName: string, args: any[]) => void;
51
+ type DerivedStateMap<DS> = {
52
+ [name in keyof DS]?: any[];
53
+ };
54
+ /** @internal */
55
+ export type DerivedState<DS> = {
56
+ state: DS;
57
+ deps: DerivedStateMap<DS>;
58
+ };
59
+ export declare class EffectError extends Error {
60
+ /**
61
+ * The wrapped error
62
+ */
63
+ source: any;
64
+ /**
65
+ * If effects error occurred while processed an error, the initial error.
66
+ */
67
+ initialError: Error;
68
+ constructor(source: any, initialError?: Error);
69
+ }
70
+ /**
71
+ * Global configuration, shared with all stores.
72
+ */
73
+ export type GlobalConfig = {
74
+ /**
75
+ * Clone function.
76
+ * Used to clone state and props when managing optimistic reducer and conflicting actions.
77
+ * Default implementation is a very basic algorithm using JSON.stringify. To clone complex stats,
78
+ * use a custom implementation like lodash/cloneDeep.
79
+ * @default JSON.stringify
80
+ */
81
+ clone: CloneFunction;
82
+ /**
83
+ * Compare to objets and returns if they are equal.
84
+ * Used to comparent previous and current state slice.
85
+ * @default shallow
86
+ */
87
+ comparator: ComparatorFunction;
88
+ /**
89
+ * Global callback function to handle asychronous actions rejected promise.
90
+ */
91
+ asyncErrorHandler: AsyncErrorHandler;
92
+ /**
93
+ * Tests if the error will trigger a retry of the action or will fail directly.
94
+ * Default implementation is returning true for TypeError instances only.
95
+ * @see AsynchActionBase#retryCount
96
+ */
97
+ retryOnErrorFunction: RetryOnErrorFunction;
98
+ /**
99
+ * First retry timeout. Every retry will wait x
100
+ */
101
+ autoRetryTimeout: number;
102
+ /**
103
+ * Number of retries in case of error (failed to fetch).
104
+ * If <code>0</code>, retry is globally disabled.
105
+ */
106
+ autoRetryCount: number;
107
+ /**
108
+ * Global notification function that will called when an asynchronous action succeeded,
109
+ * if and only if, an error message is specified for this action using
110
+ * <code>getErrorMessage</code>.
111
+ * If another function is set in the options, the function from the options will be used.
112
+ */
113
+ notifySuccess: NotifyFunc;
114
+ /**
115
+ * Global notification function that will called when an asynchronous action fails,
116
+ * if and only if, an error message is specified for this action using
117
+ * <code>getErrorMessage</code>.
118
+ * If another function is set in the options, the function from the options will be used.
119
+ */
120
+ notifyError: NotifyFunc;
121
+ /**
122
+ * Global notification function that will injected in onDone and onFail of an asynchronous actions and onActionDone of a synchronous function,
123
+ * If another function is set in the options, the function from the options will be used.
124
+ */
125
+ notifyWarning: NotifyFunc;
126
+ /**
127
+ * A default error message provider.
128
+ * Used to return generic messages on generic HTTP errors
129
+ */
130
+ getErrorMessage: (error: Error) => string;
131
+ /**
132
+ * Default middlewares. Store middleware array will be concatenated with this one.
133
+ * By default contains only the optimistic middleware.
134
+ */
135
+ defaultMiddlewares: MiddlewareFactory<any, any, any>[];
136
+ };
137
+ /** @internal */
138
+ export declare const globalConfig: GlobalConfig;
139
+ export declare function setGlobalConfig(overrideConfig: Partial<GlobalConfig>): void;
140
+ /**
141
+ * Type guard function to test if an action is a asynchronous action.
142
+ */
143
+ export declare function isAsyncAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncAction<S, F, A, P, DS, FxRes>;
144
+ /**
145
+ * Type guard function to test if an action is a synchronous action.
146
+ */
147
+ export declare function isSimpleSyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is SimpleSyncAction<S, F, P, DS, FxRes>;
148
+ /**
149
+ * Type guard function to test if an action is a synchronous action.
150
+ */
151
+ export declare function isSyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is SyncAction<S, F, A, P, DS, FxRes>;
152
+ export declare function isAsyncGetPromiseAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncActionPromise<S, F, A, P, DS, FxRes>;
153
+ export declare function isAsyncGetPromiseGetAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
154
+ /** @internal */
155
+ export declare function computeAsyncActionInput<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: AsyncAction<S, F, A, P, DS, FxRes>): AsyncActionPromise<S, F, A, P, DS, FxRes>;
156
+ /** @internal */
157
+ export declare function buildLoadingMap<A>(source: InternalLoadingMap<A>, actionName: keyof A, promiseId: string, loading: boolean): InternalLoadingMap<A>;
158
+ /** @internal */
159
+ export declare function updateErrorMap<A>(source: ErrorParallelMap<A>, actionName: keyof A, promiseId: string, error: Error): ErrorParallelMap<A>;
160
+ export declare class ParallelActionError extends Error {
161
+ promiseIds: PromiseIdErrorMap;
162
+ constructor(promiseIds: PromiseIdErrorMap);
163
+ }
164
+ export declare function buildErrorMap<A>(map: ErrorParallelMap<A>): ErrorMap<A>;
165
+ /** @internal */
166
+ export declare function retryPromiseDecorator<S, DS, F extends (...args: any[]) => Promise<any>, A, P>(promiseProvider: PromiseProvider<S, DS, F, A, P>, maxCalls?: number, delay?: number, isRetryError?: (e: Error) => boolean): PromiseProvider<S, DS, F, A, P>;
167
+ export type Ref<P> = {
168
+ current: P;
169
+ };
170
+ /** @internal */
171
+ export declare function createRef<U>(init?: U): Ref<U>;
172
+ /** @internal */
173
+ export declare function buildInvocationContextBase<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>): ContextWithDerived<S, DS, P>;
174
+ /** @internal */
175
+ export declare function buildOnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>): OnMountInvocationContext<S, A, P>;
176
+ /** @internal */
177
+ export declare function buildOnUnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, abortedActions: AbortedActions<A>): OnUnMountInvocationContext<S, A, P>;
178
+ /** @internal */
179
+ export declare function buildOnPropChangeEffects<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, indices: number[], index: number, isInit: boolean, getInitialState: (p: P) => S): OnPropsChangeEffectsContext<S, DS, P>;
180
+ /** @internal */
181
+ export declare function addStateToContext<T, S>(ctx: T, stateRef: Ref<S>): T & ContextState<S>;
182
+ /** @internal */
183
+ export declare function addContextActions<T, A>(ctx: T, actionsRef: Ref<A>): T & InvocationContextActions<A>;
184
+ /** @internal */
185
+ export declare function isFuncConfig<S, A extends DecoratedActions, P = {}, DS = {}>(config: StoreConfig<S, A, P, DS>): config is StoreConfigFunc<S, A, P, DS>;
186
+ /** @internal */
187
+ export declare function decorateSimpleSyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(actionName: keyof A, action: SimpleSyncAction<S, F, P, DS>, stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, initializedRef: Ref<boolean>, options: StoreOptions<S, A, P, DS>, setState: SetStateFunc<S, A>): (...args: Parameters<F>) => void;
188
+ /** @internal */
189
+ export declare function decorateSyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(actionName: keyof A, action: SyncAction<S, F, A, P, DS>, stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>, initializedRef: Ref<boolean>, timeoutMap: Ref<TimeoutMap<A>>, options: StoreOptions<S, A, P, any>, setState: SetStateFunc<S, A>, clearError: ClearErrorFunc<A>): (...args: Parameters<F>) => void;
190
+ /** @internal */
191
+ export declare function decorateAsyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(context: AsyncActionExecContext<S, DS, F, A, P>): (...args: Parameters<F>) => Promise<any>;
192
+ /** @internal */
193
+ export declare function isLoadingImpl<A, K extends keyof A>(loadingMap: InternalLoadingMap<A>, ...props: (K | [K, string])[]): boolean;
194
+ export declare const DEFAULT_PROMISE_ID = "__def__";
195
+ /** @internal */
196
+ export declare function areSameArgs(args1: any[], args2: any[]): boolean;
197
+ /** @internal */
198
+ export declare function computeDerivedValues<S, A, P, DS>(s: Ref<S>, p: Ref<P>, derivedStateRef: Ref<DerivedState<DS>>, options: StoreOptions<S, A, P, DS>, derivedStateOverrideRef?: Ref<DS>): boolean;
199
+ /** @internal */
200
+ export declare function fixDerivedDeps<S, A, P, DS>(options: StoreOptions<S, A, P, DS>): void;
201
+ /** @internal */
202
+ export declare function onPropChange<S, P, A, DS>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, oldProps: P, actionsRef: Ref<A>, options: StoreOptions<S, A, P, DS>, getInitialState: (p: P) => S, setState: SetStateFunc<S, A>, isInit: boolean, isDeferred: boolean): void;
203
+ /** @internal */
204
+ export declare function runMiddlewares<S, A extends DecoratedActions, P>(middlewares: Middleware<S, A, P>[], oldState: S, newState: S, loading: boolean, actionName: keyof A, actionType: 'preEffects' | 'effects' | 'errorEffects' | null, isAsync: boolean, actionCtx: any): {
205
+ newState: S;
206
+ newLoading: boolean;
207
+ };
208
+ export {};