-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtypes.ts
64 lines (54 loc) · 1.9 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { Patch } from "immer";
import type { Operation, Scope } from "effection";
import type { AnyAction, AnyState } from "../types.ts";
import type { LoaderOutput } from "./slice/loaders.ts";
import type { TableOutput } from "./slice/table.ts";
import { BaseCtx } from "../mod.ts";
import { createRun } from "./run.ts";
export type StoreUpdater<S extends AnyState> = (s: S) => S | void;
export type Listener = () => void;
export interface UpdaterCtx<S extends AnyState> extends BaseCtx {
updater: StoreUpdater<S> | StoreUpdater<S>[];
patches: Patch[];
}
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
export interface BaseSchema<TOutput> {
initialState: TOutput;
schema: string;
name: string;
}
export type Output<O extends { [key: string]: BaseSchema<unknown> }> = {
[key in keyof O]: O[key]["initialState"];
};
export interface FxMap {
loaders: <M extends AnyState>(s: string) => LoaderOutput<M, AnyState>;
cache: (s: string) => TableOutput<any, AnyState>;
[key: string]: (name: string) => BaseSchema<unknown>;
}
export type FxSchema<S extends AnyState, O extends FxMap = FxMap> =
& {
[key in keyof O]: ReturnType<O[key]>;
}
& { update: FxStore<S>["update"] };
export interface FxStore<S extends AnyState> {
getScope: () => Scope;
getState: () => S;
subscribe: (fn: Listener) => () => void;
update: (u: StoreUpdater<S> | StoreUpdater<S>[]) => Operation<UpdaterCtx<S>>;
reset: (ignoreList?: (keyof S)[]) => Operation<UpdaterCtx<S>>;
run: ReturnType<typeof createRun>;
// deno-lint-ignore no-explicit-any
dispatch: (a: AnyAction | AnyAction[]) => any;
replaceReducer: (r: (s: S, a: AnyAction) => S) => void;
getInitialState: () => S;
// deno-lint-ignore no-explicit-any
[Symbol.observable]: () => any;
}
export interface QueryState {
cache: TableOutput<any, any>["initialState"];
loaders: LoaderOutput<any, any>["initialState"];
}