8000 expose rootState in module getters and actions · vuejs/v2.vuejs.org@2e46bf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e46bf9

Browse files
committed
expose rootState in module getters and actions
1 parent b2f2514 commit 2e46bf9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class Store {
120120
dispatch,
121121
commit,
122122
getters: store.getters,
123-
state: getNestedState(store.state, path)
123+
state: getNestedState(store.state, path),
124+
rootState: store.state
124125
}, payload, cb)
125126
if (!isPromise(res)) {
126127
res = Promise.resolve(res)
@@ -276,7 +277,7 @@ function extractModuleGetters (getters = {}, modules = {}, path = []) {
276277
return
277278
}
278279
getters[getterKey] = function wrappedGetter (state) {
279-
return rawGetter(getNestedState(state, modulePath))
280+
return rawGetter(getNestedState(state, modulePath), state)
280281
}
281282
})
282283
}

test/unit/test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,10 @@ describe('Vuex', () => {
378378
let calls = 0
379379
const makeAction = n => {
380380
return {
381-
[TEST] ({ state }) {
381+
[TEST] ({ state, rootState }) {
382382
calls++
383383
expect(state.a).to.equal(n)
384+
expect(rootState).to.equal(store.state)
384385
}
385386
}
386387
}
@@ -424,7 +425,12 @@ describe('Vuex', () => {
424425

425426
it('module: getters', function () {
426427
const makeGetter = n => ({
427-
[`getter${n}`]: state => state.a
428+
[`getter${n}`]: (state, rootState) => {
429+
if (rootState) {
430+
expect(rootState).to.equal(store.state)
431+
}
432+
return state.a
433+
}
428434
})
429435
const store = new Vuex.Store({
430436
state: {

0 commit comments

Comments
 (0)
0