Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove old watchers on strict mode
Browse files Browse the repository at this point in the history
AlexandrosDa007 committed Jan 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent bd90746 commit 0602eee
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/store-util.js
Original file line number Diff line number Diff line change
@@ -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.`)
}
4 changes: 3 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<S> {
getters?: GetterTree<S, S>;
modules?: ModuleTree<S>;
}): void;

_strictModeWatcherUnsubscribe?: WatchStopHandle;
}

export const storeKey: string;

0 comments on commit 0602eee

Please sign in to comment.