diff --git a/packages/r-store/index.d.ts b/packages/r-store/index.d.ts index a18b133..aafac2d 100644 --- a/packages/r-store/index.d.ts +++ b/packages/r-store/index.d.ts @@ -66,7 +66,8 @@ export declare function createState>(setup: Se export declare const createStore: >(creator: Creator) => UseSelectorWithStore; /** - * @deprecated new version of React 'StrictMode' cause lifeCycle function not work as expect + * @deprecated + * new version of React 'StrictMode' cause lifeCycle function not work as expect * try to disable `StrictMode` to fix this issue */ export declare function createStoreWithComponent>(props: CreateStoreWithComponentProps, T>): ({ children }: { @@ -74,7 +75,8 @@ export declare function createStoreWithComponent ReactElement; /** - * @deprecated new version of React 'StrictMode' cause lifeCycle function not work as expect + * @deprecated + * new version of React 'StrictMode' cause lifeCycle function not work as expect * try to disable `StrictMode` to fix this issue */ export declare function createStoreWithComponent

, T extends Record>(props: CreateStoreWithComponentProps): ({ children }: { @@ -293,7 +295,8 @@ export declare type WithActionsProps = { }; /** - * @deprecated use `withSelectorOptions` instead + * @deprecated + * use `withSelectorOptions` instead */ export declare const withDeepSelector: typeof withSelectorOptions; diff --git a/packages/r-store/src/shared/controller.ts b/packages/r-store/src/shared/controller.ts index dc105e6..b0c63c3 100644 --- a/packages/r-store/src/shared/controller.ts +++ b/packages/r-store/src/shared/controller.ts @@ -64,6 +64,8 @@ export class Controller { _devWithStable: any; + _devVersion: string; + _devType: any; _devResult: any; @@ -109,9 +111,13 @@ export class Controller { this._namespace !== InternalNameSpace.$$__redux_dev_tool__$$ ) { this._list = _list; - + this._list.add(this); } + + if (__DEV__) { + this._devVersion = __VERSION__; + } } notify = () => { @@ -131,7 +137,7 @@ export class Controller { this._lifeCycle.canUpdateComponent = false; } - + this._listeners.forEach((f) => f()); }; diff --git a/packages/r-store/src/shared/dev.ts b/packages/r-store/src/shared/dev.ts index 017feed..366f425 100644 --- a/packages/r-store/src/shared/dev.ts +++ b/packages/r-store/src/shared/dev.ts @@ -101,7 +101,7 @@ const sendToDevTools = (action: Action) => { const { getUpdatedState, ...rest } = action; try { const state = getUpdatedState(); - + getDevToolInstance().send(rest, state); } catch (e) { console.log(e); @@ -168,6 +168,10 @@ export const connectDevTool = ( // create a subscribe controller to listen to the state change, because some state change may not trigger by the `action` const controller = new Controller(subscribe, lifeCycle, temp, InternalNameSpace.$$__redux_dev_tool__$$, onUpdateWithoutAction); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + controller._devReduxOptions = options; + devController[name] = controller; controller.run(); diff --git a/packages/r-store/src/shared/hook.ts b/packages/r-store/src/shared/hook.ts index f9c99c1..f010e40 100644 --- a/packages/r-store/src/shared/hook.ts +++ b/packages/r-store/src/shared/hook.ts @@ -96,9 +96,9 @@ export const createHook = , C extends Record(type: "default" | "deep" | "deep-stable" | "shallow" | "shallow-stable") => { - const currentIsDeep = type === 'default' ? deepSelector : type === 'deep' || type === 'deep-stable'; + const currentIsDeep = type === "default" ? deepSelector : type === "deep" || type === "deep-stable"; - const currentIsStable = type === 'default' ? stableSelector : type === 'deep-stable' || type === 'shallow-stable'; + const currentIsStable = type === "default" ? stableSelector : type === "deep-stable" || type === "shallow-stable"; return (selector?: (state: DeepReadonly> & C) => P) => { const ref = useRef

>>(); @@ -248,9 +248,16 @@ export const createHook = , C extends Record controller.stop(); + return () => { + if (__DEV__) { + delDevController(controller, initialState); + } + controller.stop(); + }; }; typedUseSelector.cleanReactiveHooks = () => { diff --git a/packages/r-store/src/state/_internal.ts b/packages/r-store/src/state/_internal.ts index 8327134..2899ede 100644 --- a/packages/r-store/src/state/_internal.ts +++ b/packages/r-store/src/state/_internal.ts @@ -104,7 +104,7 @@ export function internalCreateState, P extends const stableSelector = selectorOptions?.stableSelector ?? false; if (__DEV__ && reduxDevTool) { - actions = connectDevTool(namespaceOptions.namespace, actions, rawState, reactiveState) as P; + actions = connectDevTool(namespaceOptions.namespace, actions, rawState, reactiveState, namespaceOptions) as P; } const useSelector = createHook(reactiveState, rawState, lifeCycle, deepSelector, stableSelector, namespaceOptions.namespace, actions as P & L); diff --git a/packages/r-store/src/state/middleware/withPersist.ts b/packages/r-store/src/state/middleware/withPersist.ts index 74d4e58..ace6bbc 100644 --- a/packages/r-store/src/state/middleware/withPersist.ts +++ b/packages/r-store/src/state/middleware/withPersist.ts @@ -141,6 +141,10 @@ export function withPersist, P extends Record< if (__DEV__) { setDevController(ControllerInstance, initialState); + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + ControllerInstance._devPersistOptions = options; } return {