From 0602eeea5a7b8f1a0758af581d7e3b3bb558dcc4 Mon Sep 17 00:00:00 2001 From: Alex Daltsis Date: Sat, 18 Jan 2025 00:23:22 +0200 Subject: [PATCH] fix: remove old watchers on strict mode --- src/store-util.js | 3 ++- types/index.d.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/store-util.js b/src/store-util.js index e3ba18609..4aac002cd 100644 --- a/src/store-util.js +++ b/src/store-util.js @@ -269,7 +269,8 @@ function registerGetter (store, type, rawGetter, local) { } function enableStrictMode (store) { - watch(() => store._state.data, () => { + store._strictModeWatcherUnsubscribe && store._strictModeWatcherUnsubscribe(); + store._strictModeWatcherUnsubscribe = watch(() => store._state.data, () => { if (__DEV__) { assert(store._committing, `do not mutate vuex store state outside mutation handlers.`) } diff --git a/types/index.d.ts b/types/index.d.ts index a9a94de82..570231a5d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,4 @@ -import { App, WatchOptions, InjectionKey } from "vue"; +import { App, WatchOptions, InjectionKey , WatchStopHandle } from "vue"; // augment typings of Vue.js import "./vue"; @@ -41,6 +41,8 @@ export declare class Store { getters?: GetterTree; modules?: ModuleTree; }): void; + + _strictModeWatcherUnsubscribe?: WatchStopHandle; } export const storeKey: string;