1 | import { IMiddlewareEvent, IMiddlewareHandler } from "../internal";
|
2 | export interface IActionTrackingMiddlewareHooks<T> {
|
3 | filter?: (call: IMiddlewareEvent) => boolean;
|
4 | onStart: (call: IMiddlewareEvent) => T;
|
5 | onResume: (call: IMiddlewareEvent, context: T) => void;
|
6 | onSuspend: (call: IMiddlewareEvent, context: T) => void;
|
7 | onSuccess: (call: IMiddlewareEvent, context: T, result: any) => void;
|
8 | onFail: (call: IMiddlewareEvent, context: T, error: any) => void;
|
9 | }
|
10 | /**
|
11 | * Note: Consider migrating to `createActionTrackingMiddleware2`, it is easier to use.
|
12 | *
|
13 | * Convenience utility to create action based middleware that supports async processes more easily.
|
14 | * All hooks are called for both synchronous and asynchronous actions. Except that either `onSuccess` or `onFail` is called
|
15 | *
|
16 | * The create middleware tracks the process of an action (assuming it passes the `filter`).
|
17 | * `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.
|
18 | *
|
19 | * See the `atomic` middleware for an example
|
20 | *
|
21 | * @param hooks
|
22 | * @returns
|
23 | */
|
24 | export declare function createActionTrackingMiddleware<T = any>(hooks: IActionTrackingMiddlewareHooks<T>): IMiddlewareHandler;
|