clean-redux
Version:
Utilities for implementing clean architecture using Redux
37 lines (36 loc) • 1.8 kB
TypeScript
import type { NonPostableEvt } from "evt";
import type { Middleware, ActionCreator, ActionCreatorWithPayload, ActionCreatorWithoutPayload } from "@reduxjs/toolkit";
export declare function createMiddlewareEvtActionFactory<Usecase extends {
name: string;
} & ({
actions: Record<string, ActionCreator<any>>;
} | {
reducer: null;
})>(usecases: readonly Usecase[]): {
createMiddlewareEvtAction: () => {
/** NOTE: We use an expended version of the type so that,
* when the cursor hovers evtAction we get an explicit type instead of
* a composition of union:
* This: https://user-images.githubusercontent.com/6702424/147380322-bf2fa468-0a1c-4961-a7d8-16eaa14b6c4e.png
* Instead of this: https://user-images.githubusercontent.com/6702424/147380353-9956a98a-9f9c-4811-a8b4-16cd1e4e76ca.png
* Don't try, however, to work edit the expanded version. Start from the factorized
* form by uncommenting the following line and the helper types it leverages.
*/
evtAction: import("evt/lib/types/interfaces/NonPostableEvt").NonPostableEvt<{ [Key in Extract<Usecase, {
actions: unknown;
}>["name"]]: Usecase extends Extract<Usecase, {
name: Key;
actions: unknown;
}> ? { [K in keyof Usecase["actions"]]: Usecase["actions"][K] extends ActionCreatorWithoutPayload<any> ? {
sliceName: Key;
actionName: K;
} : {
sliceName: Key;
actionName: K;
payload: Usecase["actions"][K] extends ActionCreatorWithPayload<infer U, string> ? U : never;
}; }[keyof Usecase["actions"]] : never; }[Extract<Usecase, {
actions: unknown;
}>["name"]]>;
middlewareEvtAction: Middleware;
};
};