UNPKG

1.33 kBTypeScriptView Raw
1import { IMiddlewareHandler, IActionContext } from "../internal";
2export interface IActionTrackingMiddleware2Call<TEnv> extends Readonly<IActionContext> {
3 env: TEnv | undefined;
4 readonly parentCall?: IActionTrackingMiddleware2Call<TEnv>;
5}
6export interface IActionTrackingMiddleware2Hooks<TEnv> {
7 filter?: (call: IActionTrackingMiddleware2Call<TEnv>) => boolean;
8 onStart: (call: IActionTrackingMiddleware2Call<TEnv>) => void;
9 onFinish: (call: IActionTrackingMiddleware2Call<TEnv>, error?: any) => void;
10}
11/**
12 * Convenience utility to create action based middleware that supports async processes more easily.
13 * The flow is like this:
14 * - for each action: if filter passes -> `onStart` -> (inner actions recursively) -> `onFinish`
15 *
16 * Example: if we had an action `a` that called inside an action `b1`, then `b2` the flow would be:
17 * - `filter(a)`
18 * - `onStart(a)`
19 * - `filter(b1)`
20 * - `onStart(b1)`
21 * - `onFinish(b1)`
22 * - `filter(b2)`
23 * - `onStart(b2)`
24 * - `onFinish(b2)`
25 * - `onFinish(a)`
26 *
27 * The flow is the same no matter if the actions are sync or async.
28 *
29 * See the `atomic` middleware for an example
30 *
31 * @param hooks
32 * @returns
33 */
34export declare function createActionTrackingMiddleware2<TEnv = any>(middlewareHooks: IActionTrackingMiddleware2Hooks<TEnv>): IMiddlewareHandler;