-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LiJun
committed
Oct 7, 2019
1 parent
eeb466d
commit f881293
Showing
4 changed files
with
98 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
export declare namespace CubeState { | ||
export interface StoreItem { | ||
name: string; | ||
useStore: Function; | ||
effects: Record<string, Function>; | ||
reducers: Record<string, Function>; | ||
getState: Function; | ||
} | ||
|
||
export type StoreMap = Record<string, StoreItem>; | ||
|
||
export interface InitOpt { | ||
effectMeta?(config: { storeMap: StoreMap }): object; | ||
} | ||
|
||
export interface Opt<S, R, E> { | ||
name: string; | ||
state: S; | ||
reducers?: R extends undefined ? undefined : R; | ||
effects?: E extends undefined ? undefined : E; | ||
[k: string]: any; | ||
} | ||
|
||
export type StateSelector<S, P> = (state: S) => P; | ||
|
||
export interface EnhanceReducers<S> { | ||
[key: string]: EnhanceReducerFn<S>; | ||
} | ||
export type EnhanceReducerFn<S> = (state: S, ...payload: any) => any; | ||
|
||
export type Reducers<R> = { | ||
[K in keyof R]: ReducerFn<R[K]>; | ||
}; | ||
export type ReducerFn<F> = F extends (state: infer S, ...args: infer A) => any | ||
? (...args: A) => any | ||
: unknown; | ||
|
||
export interface EnhanceEffects<S> { | ||
[key: string]: EnhanceEffectFn<S>; | ||
} | ||
export type EnhanceEffectFn<S> = ( | ||
meta: EffectMeta<S>, | ||
...args: any | ||
) => Promise<any>; | ||
|
||
export interface EffectMeta<S> { | ||
call<A, R>(fn: () => R, ...extra: any): Promise<R>; | ||
call<A, R>(fn: CalledFn<A, R>, payload: A, ...extra: any): Promise<R>; | ||
update(newState: Partial<S>): any; | ||
select<P>(selector: StateSelector<S, P>): P; | ||
} | ||
|
||
export type CalledFn<A, R> = (payload: A) => R; | ||
|
||
export type Effects<E> = { | ||
[K in keyof E]: EffectFn<E[K]>; | ||
}; | ||
export type EffectFn<F> = F extends ( | ||
meta: infer U, | ||
...args: infer A | ||
) => Promise<any> | ||
? (...args: A) => ReturnType<F> | ||
: unknown; | ||
|
||
export type Updater<S> = (oldState: S, nextState: S) => any; | ||
|
||
export type ErrorFn = (e: Error, meta: object) => any; | ||
export type ReducerHook = (result: any, reducerName: string) => any; | ||
export type BeforeEffectHook = (payload: any, meta: object) => any; | ||
export type AfterEffectHook = (result: any, meta: object) => any; | ||
export interface Plugin { | ||
onError?: ErrorFn; | ||
beforeReducer?: ReducerHook; | ||
afterReducer?: ReducerHook; | ||
beforeEffect?: BeforeEffectHook; | ||
afterEffect?: AfterEffectHook; | ||
extraReducers?: Function; | ||
} | ||
export type HookMap = { | ||
[K in keyof Plugin]: Function[]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters