repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

Eric Bower · 10 Feb 24

types.ts

 1import type { Instruction, Operation } from "./deps.ts";
 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<
24  M extends AnyState = AnyState,
25> extends LoaderItemState<M> {
26  isIdle: boolean;
27  isLoading: boolean;
28  isError: boolean;
29  isSuccess: boolean;
30  isInitialLoading: boolean;
31}
32
33export type LoaderPayload<M extends AnyState> =
34  & Pick<LoaderItemState<M>, "id">
35  & Partial<Pick<LoaderItemState<M>, "message" | "meta">>;
36
37// deno-lint-ignore no-explicit-any
38export type AnyState = Record<string, any>;
39
40// deno-lint-ignore no-explicit-any
41export interface Payload<P = any> {
42  payload: P;
43}
44
45export interface Action {
46  type: string;
47}
48
49export type ActionFn = () => { toString: () => string };
50export type ActionFnWithPayload<P = any> = (p: P) => { toString: () => string };
51
52// https://github.com/redux-utilities/flux-standard-action
53export interface AnyAction extends Action {
54  payload?: any;
55  meta?: any;
56  error?: boolean;
57}
58
59export interface ActionWithPayload<P> extends AnyAction {
60  payload: P;
61}