-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
完善类型-新增 isDeepWarch 选项,删除 sameValueExecuteWatch 选项
- Loading branch information
Showing
3 changed files
with
165 additions
and
100 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,44 +1,60 @@ | ||
interface IObject extends Object { | ||
export interface AnyObject extends Object { | ||
[key: string]: any | ||
} | ||
interface IArray extends Array<any> { | ||
export interface AnyArray extends Array<any> { | ||
[key: string]: any | ||
} | ||
|
||
interface IState extends Object { | ||
/* Store Type */ | ||
export type ObjectKey<T> = keyof T | ||
|
||
export interface IState extends Object { | ||
[key: string]: any | ||
} | ||
|
||
interface IActions extends Object { | ||
export interface IActions extends Object { | ||
[key: string]: Function | ||
} | ||
|
||
interface IStoreArg<S, A> { | ||
state?: IState | ||
actions?: A & IActions & ThisType<S & A & IStoreApi>, | ||
} | ||
|
||
interface IStoreOptionsArg { | ||
sameValueExecuteWatch?: boolean | ||
export type ITrackStore<S> = { | ||
[Props in keyof S]?: Set<Function> | ||
} | ||
|
||
type ITrackStore = { | ||
[key: string]: Set<Function> | ||
export interface IStoreApi<S> { | ||
watch( | ||
key: ObjectKey<S> | ObjectKey<S>[], | ||
callback: (key: string, value: any) => any | ||
): any | ||
watchEffect( | ||
key: ObjectKey<S> | ObjectKey<S>[], | ||
callback: (key: string, value: any) => any | ||
): any | ||
deleteWatch( | ||
key: ObjectKey<S> | ObjectKey<S>[], | ||
callback: (key: string, value: any) => any | ||
): any | ||
} | ||
|
||
interface IInstance { | ||
export interface IInstance<S extends IState, A extends IActions> { | ||
id: number | ||
trackStore: ITrackStore | ||
trackStore: ITrackStore<S> | ||
state: IState | ||
actions: IActions, | ||
actions: A & ThisType<IStoreProxy<S, A>> | ||
options: IStoreOptionsArg | ||
} | ||
|
||
interface IStoreApi { | ||
watch(key: string | string[], callback: Function): any | ||
watchEffect(key: string | string[], callback: Function): any | ||
deleteWatch(key: string | string[], callback: Function): any | ||
[key: string]: any | ||
export interface IStoreArg<S extends IState, A extends IActions> { | ||
state: S | ||
actions: A & ThisType<IStoreProxy<S, A>> | ||
} | ||
|
||
export interface IStoreOptionsArg { | ||
isDeepWatch?: boolean | ||
} | ||
|
||
export { IObject, IArray, IState, IActions, IStoreArg, IStoreOptionsArg, ITrackStore, IInstance, IStoreApi } | ||
export type IStoreProxy<S extends IState, A extends IActions> = S & | ||
A & | ||
IStoreApi<S> & { | ||
id: number | ||
trackStore: ITrackStore<S> | ||
} |
Oops, something went wrong.