Skip to content

Commit 4f183aa

Browse files
committed
refactor: rename vm to state since in vue 3 we don't use vm anymore
1 parent bfb6ca5 commit 4f183aa

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/store.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export class Store {
5151
// and collects all module getters inside this._wrappedGetters
5252
installModule(this, state, [], this._modules.root)
5353

54-
// initialize the store vm, which is responsible for the reactivity
54+
// initialize the store state, which is responsible for the reactivity
5555
// (also registers _wrappedGetters as computed properties)
56-
resetStoreVM(this, state)
56+
resetStoreState(this, state)
5757

5858
// apply plugins
5959
plugins.forEach(plugin => plugin(this))
@@ -69,7 +69,7 @@ export class Store {
6969
}
7070

7171
get state () {
72-
return this._vm._data.$$state
72+
return this._state.data
7373
}
7474

7575
set state (v) {
@@ -180,7 +180,7 @@ export class Store {
180180

181181
replaceState (state) {
182182
this._withCommit(() => {
183-
this._vm._data.$$state = state
183+
this._state.data = state
184184
})
185185
}
186186

@@ -195,7 +195,7 @@ export class Store {
195195
this._modules.register(path, rawModule)
196196
installModule(this, this.state, path, this._modules.get(path), options.preserveState)
197197
// reset store to update getters...
198-
resetStoreVM(this, this.state)
198+
resetStoreState(this, this.state)
199199
}
200200

201201
unregisterModule (path) {
@@ -246,12 +246,12 @@ function resetStore (store, hot) {
246246
const state = store.state
247247
// init all modules
248248
installModule(store, state, [], store._modules.root, true)
249-
// reset vm
250-
resetStoreVM(store, state, hot)
249+
// reset state
250+
resetStoreState(store, state, hot)
251251
}
252252

253-
function resetStoreVM (store, state, hot) {
254-
const oldVm = store._vm
253+
function resetStoreState (store, state, hot) {
254+
const oldState = store._state
255255

256256
// bind store public getters
257257
store.getters = {}
@@ -277,23 +277,21 @@ function resetStoreVM (store, state, hot) {
277277
//
278278
// New impl with reactive. Defining redundunt keys to make it as close as
279279
// the old impl api.
280-
store._vm = reactive({
281-
_data: {
282-
$$state: state
283-
}
280+
store._state = reactive({
281+
data: state
284282
})
285283

286-
// enable strict mode for new vm
284+
// enable strict mode for new state
287285
if (store.strict) {
288286
enableStrictMode(store)
289287
}
290288

291-
if (oldVm) {
289+
if (oldState) {
292290
if (hot) {
293291
// dispatch changes in all subscribed watchers
294292
// to force getter re-evaluation for hot reloading.
295293
store._withCommit(() => {
296-
oldVm._data.$$state = null
294+
oldState.data = null
297295
})
298296
}
299297
// TODO: I think we don't need this anymore since we're not using vm?
@@ -394,7 +392,7 @@ function makeLocalContext (store, namespace, path) {
394392
}
395393

396394
// getters and state object must be gotten lazily
397-
// because they will be changed by vm update
395+
// because they will be changed by state update
398396
Object.defineProperties(local, {
399397
getters: {
400398
get: noNamespace
@@ -484,7 +482,7 @@ function registerGetter (store, type, rawGetter, local) {
484482
}
485483

486484
function enableStrictMode (store) {
487-
watch(() => store._vm._data.$$state, () => {
485+
watch(() => store._state.data, () => {
488486
if (process.env.NODE_ENV !== 'production') {
489487
assert(store._committing, `do not mutate vuex store state outside mutation handlers.`)
490488
}

0 commit comments

Comments
 (0)