1 | import { IMiddlewareEvent, IMiddlewareHandler } from "../core/action";
|
2 | /**
|
3 | * Convenience utility to create action based middleware that supports async processes more easily.
|
4 | * All hooks are called for both synchronous and asynchronous actions. Except that either `onSuccess` or `onFail` is called
|
5 | *
|
6 | * The create middleware tracks the process of an action (assuming it passes the `filter`).
|
7 | * `onResume` can return any value, which will be passed as second argument to any other hook. This makes it possible to keep state during a process.
|
8 | *
|
9 | * See the `atomic` middleware for an example
|
10 | *
|
11 | * @export
|
12 | * @template T
|
13 | * @template any
|
14 | * @param {{
|
15 | * filter?: (call: IMiddlewareEvent) => boolean
|
16 | * onStart: (call: IMiddlewareEvent) => T
|
17 | * onResume: (call: IMiddlewareEvent, context: T) => void
|
18 | * onSuspend: (call: IMiddlewareEvent, context: T) => void
|
19 | * onSuccess: (call: IMiddlewareEvent, context: T, result: any) => void
|
20 | * onFail: (call: IMiddlewareEvent, context: T, error: any) => void
|
21 | * }} hooks
|
22 | * @returns {IMiddlewareHandler}
|
23 | */
|
24 | export declare function createActionTrackingMiddleware<T = any>(hooks: {
|
25 | filter?: (call: IMiddlewareEvent) => boolean;
|
26 | onStart: (call: IMiddlewareEvent) => T;
|
27 | onResume: (call: IMiddlewareEvent, context: T) => void;
|
28 | onSuspend: (call: IMiddlewareEvent, context: T) => void;
|
29 | onSuccess: (call: IMiddlewareEvent, context: T, result: any) => void;
|
30 | onFail: (call: IMiddlewareEvent, context: T, error: any) => void;
|
31 | }): IMiddlewareHandler;
|