@mmuscat/angular-actions
Version:
A tiny (1kb) state management library for Angular Composition API.
23 lines (22 loc) • 1.15 kB
TypeScript
import { ValueToken } from "@mmuscat/angular-composition-api";
import { Observable } from "rxjs";
export declare type Action<T extends string, U extends {} = {}> = U & {
readonly kind: T;
};
export interface DispatchAction<T extends string> extends Observable<Action<T>> {
(): void;
readonly kind: string;
}
export interface DispatchActionWithProps<T extends string, U extends ActionPropsFactory<any, any>> extends Observable<Action<T, ReturnType<U>>> {
(...args: Parameters<U>): void;
readonly kind: string;
}
export declare type ActionDispatcher<T extends string, U extends ActionPropsFactory<any, any>> = DispatchAction<T> | DispatchActionWithProps<T, U>;
interface ActionStatic {
new <T extends string, U extends ActionPropsFactory<any, any>>(kind: T, factory: U): ValueToken<DispatchActionWithProps<T, U>>;
new <T extends string>(kind: T): ValueToken<DispatchAction<T>>;
}
export declare type ActionPropsFactory<TParams extends any[], TReturn extends {}> = (...args: TParams) => TReturn;
export declare const Action: ActionStatic;
export declare function props<T extends {}>(): ActionPropsFactory<[T], T>;
export {};