Vlad
·
2025-06-15
types.ts
1import type { Instruction, Operation } from "effection";
2
3export interface Computation<T = unknown> {
4 // deno-lint-ignore no-explicit-any
5 [Symbol.iterator](): Iterator<Instruction, T, any>;
6}
7
8export type Next = () => Operation<void>;
9
10export type IdProp = string | number;
11export type LoadingStatus = "loading" | "success" | "error" | "idle";
12export interface LoaderItemState<
13 M extends Record<string, unknown> = Record<IdProp, unknown>,
14> {
15 id: string;
16 status: LoadingStatus;
17 message: string;
18 lastRun: number;
19 lastSuccess: number;
20 meta: M;
21}
22
23export interface LoaderState<M extends AnyState = AnyState>
24 extends LoaderItemState<M> {
25 isIdle: boolean;
26 isLoading: boolean;
27 isError: boolean;
28 isSuccess: boolean;
29 isInitialLoading: boolean;
30}
31
32export type LoaderPayload<M extends AnyState> = Pick<LoaderItemState<M>, "id"> &
33 Partial<Pick<LoaderItemState<M>, "message" | "meta">>;
34
35// deno-lint-ignore no-explicit-any
36export type AnyState = Record<string, any>;
37
38// deno-lint-ignore no-explicit-any
39export interface Payload<P = any> {
40 payload: P;
41}
42
43export interface Action {
44 type: string;
45 [extraProps: string]: any;
46}
47
48export type ActionFn = () => { toString: () => string };
49export type ActionFnWithPayload<P = any> = (p: P) => { toString: () => string };
50
51// https://github.com/redux-utilities/flux-standard-action
52export interface AnyAction extends Action {
53 payload?: any;
54 meta?: any;
55 error?: boolean;
56 [extraProps: string]: any;
57}
58
59export interface ActionWithPayload<P> extends AnyAction {
60 payload: P;
61}