forked from storeon/storeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
29 lines (23 loc) · 1.18 KB
/
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
type DataTypes<Map, Key extends keyof Map> =
Map extends never ? [any?] : (Map[Key] extends (never | undefined) ? [never?] : [Map[Key]])
declare namespace createStore {
export type Dispatch<EventsDataTypesMap> = (<Event extends keyof EventsDataTypesMap>(
event: Event, ...data: DataTypes<Partial<EventsDataTypesMap>, Event>) => void) & {___events: EventsDataTypesMap};
export interface Store<State = unknown, EventsDataTypesMap = any> {
readonly on: <Event extends keyof EventsDataTypesMap>(
event: Event,
handler: (state: Readonly<State>, data: EventsDataTypesMap[Event]) => Partial<State> | Promise<void> | null | void
) => () => void;
readonly dispatch: Dispatch<EventsDataTypesMap>;
readonly get: () => State;
}
export type Module<State, EventsDataTypesMap = any> = (store: Store<State, EventsDataTypesMap>) => void;
export interface StoreonEvents<State> {
'@init': never;
'@changed': State;
}
}
declare function createStore<State, EventsDataTypesMap = any>(
modules: Array<createStore.Module<State, EventsDataTypesMap> | false>
): createStore.Store<State, EventsDataTypesMap & createStore.StoreonEvents<State>>;
export = createStore;