diff --git a/src/index.ts b/src/index.ts index c7c190d..f564a87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,10 +10,7 @@ import { IProxyInstanceRes } from './types' -export default function xlStore< - S extends IState, - A extends IActions> ->( +function xlStore>>( storeArgs: IStoreArgs, options?: IStoreOptionsArg ): IProxyInstanceRes { @@ -25,3 +22,5 @@ export default function xlStore< return proxyInstanceRes } + +module.exports = xlStore diff --git a/src/proxy.ts b/src/proxy.ts index cd9f4c8..e6f2f3c 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -22,27 +22,27 @@ export function proxyInstance< const { state, actions, storeApi } = instance return new Proxy>(instance as any, { + // storeApi => state => actions + get(_, prop: string) { - if (prop in instance) { - return instance[prop as ObjectKey>] - } else if (prop in storeApi) { + if (prop in storeApi) { return storeApi[prop as ObjectKey>] } else if (prop in state) { return state[prop] } else if (prop in actions) { return actions[prop] } else { - throw new Error(`不能获取 ${prop}`) + return undefined } }, set(_, prop: string, value: any) { - if (prop in instance || prop in storeApi) { + if (prop in storeApi) { throw new Error(`${prop} 是 Store 自带的不允许被修改`) } else if (prop in state) { state[prop as ObjectKey] = value return true } else if (prop in actions) { - throw new Error(`${prop} 是 actions , 不允许被修改`) + throw new Error(`${prop} 是 actions , 不允许在此被修改`) } else { throw new Error(`${prop} 不允许被修改或添加`) } diff --git a/src/types.ts b/src/types.ts index bd89926..2b60b75 100644 --- a/src/types.ts +++ b/src/types.ts @@ -62,9 +62,4 @@ export interface IStoreOptionsArg { export type IProxyInstanceRes< S extends IState, A extends IActions> -> = S & - A & - IStoreApi & { - id: number - trackStore: ITrackStore - } +> = S & A & IStoreApi