forked from developit/unistore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
29 lines (22 loc) · 964 Bytes
/
index.d.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
// T - Wrapped component props
// S - Wrapped component state
// K - Store state
// I - Injected props to wrapped component
export type Listener<K> = (state: K, action?: Action<K>) => void;
export type Unsubscribe = () => void;
export type Action<K> = (state: K, ...args: any[]) => void;
export type BoundAction = (...args: any[]) => void;
export interface Store<K> {
action(action: Action<K>): BoundAction;
setState<U extends keyof K>(update: Pick<K, U>, overwrite?: boolean, action?: Action<K>): void;
subscribe(f: Listener<K>): Unsubscribe;
unsubscribe(f: Listener<K>): void;
getState(): K;
}
export default function createStore<K>(state?: K): Store<K>;
export type ActionFn<K> = (state: K, ...args: any[]) => Promise<Partial<K>> | Partial<K> | void;
export interface ActionMap<K> {
[actionName: string]: ActionFn<K>;
}
export type ActionCreator<K> = (store: Store<K>) => ActionMap<K>;
export type StateMapper<T, K, I> = (state: K, props: T) => I;