This repository has been archived by the owner on May 20, 2022. It is now read-only.
/
index.d.ts
54 lines (35 loc) · 2.39 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
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
declare module 'react-hookstore' {
type NonUndefined<T> = T extends undefined ? never : T;
type StateCallback<TState> = (state: TState) => void;
type ReducerType<TState, TPayload = any> = (state: TState, payload: TPayload) => TState;
type SetStateType<TState> = (state: TState, callback?: StateCallback<TState>) => void;
type DispatchType<TState, TPayload = any> = (payload: TPayload, callback?: StateCallback<TState>) => void;
type StoreStateHookType<TState> = [TState, SetStateType<TState>];
type StoreDispatchHookType<TState, TPayload = any> = [TState, DispatchType<TState, TPayload>];
const defaultReducer: ReducerType<any>;
export interface StoreSpec<TState, TPayload = any> {
state: TState;
reducer: ReducerType<TState, TPayload>;
setState: SetStateType<TState> | DispatchType<TState, TPayload>;
setters: StateCallback<TState>[]
}
export interface StateStoreInterface<TState> {
readonly name: string;
getState(): TState;
setState(state: TState, callback?: StateCallback<TState>): void;
}
export interface ReducerStoreInterface<TState, TPayload = any> {
readonly name: string;
getState(): TState;
dispatch<TPayload>(payload: TPayload, callback?: StateCallback<TState>): void;
}
export function createStore<TState, TPayload = any>(name: string, state: NonUndefined<TState>, reducer: ReducerType<TState, TPayload>): ReducerStoreInterface<TState, TPayload>;
export function createStore<TState>(name: string, state: NonUndefined<TState>): StateStoreInterface<TState>;
export function createStore<TState>(name: string, state: NonUndefined<TState>, reducer: ReducerType<TState>): ReducerStoreInterface<TState>;
export function getStoreByName<TState, TPayload = any>(name: string): StateStoreInterface<TState> | ReducerStoreInterface<TState>;
export function getStoreByName<TState>(name: string): StateStoreInterface<TState> | ReducerStoreInterface<TState>;
export function useStore<TState>(identifier: string): StoreStateHookType<TState> | StoreDispatchHookType<TState>;
export function useStore<TState, TPayload = any>(identifier: string): StoreDispatchHookType<TState, TPayload>;
export function useStore<TState>(store: StateStoreInterface<TState>): StoreStateHookType<TState>;
export function useStore<TState, TPayload = any>(store: ReducerStoreInterface<TState, TPayload>): StoreDispatchHookType<TState, TPayload>;
}