Skip to content

Commit 0602eee

Browse files
fix: remove old watchers on strict mode
1 parent bd90746 commit 0602eee

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/store-util.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ function registerGetter (store, type, rawGetter, local) {
269269
}
270270

271271
function enableStrictMode (store) {
272-
watch(() => store._state.data, () => {
272+
store._strictModeWatcherUnsubscribe && store._strictModeWatcherUnsubscribe();
273+
store._strictModeWatcherUnsubscribe = watch(() => store._state.data, () => {
273274
if (__DEV__) {
274275
assert(store._committing, `do not mutate vuex store state outside mutation handlers.`)
275276
}

types/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, WatchOptions, InjectionKey } from "vue";
1+
import { App, WatchOptions, InjectionKey , WatchStopHandle } from "vue";
22

33
// augment typings of Vue.js
44
import "./vue";
@@ -41,6 +41,8 @@ export declare class Store<S> {
4141
getters?: GetterTree<S, S>;
4242
modules?: ModuleTree<S>;
4343
}): void;
44+
45+
_strictModeWatcherUnsubscribe?: WatchStopHandle;
4446
}
4547

4648
export const storeKey: string;

0 commit comments

Comments
 (0)