Skip to content

Commit 28b70d9

Browse files
committed
expose rootState in module getters and actions
1 parent 17d80ff commit 28b70d9

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
@@ -119,7 +119,8 @@ class Store {
119119
let res = handler({
120120
dispatch,
121121
commit,
122-
state: getNestedState(store.state, path)
122+
state: getNestedState(store.state, path),
123+
rootState: store.state
123124
}, payload, cb)
124125
if (!isPromise(res)) {
125126
res = Promise.resolve(res)
@@ -275,7 +276,7 @@ function extractModuleGetters (getters = {}, modules = {}, path = []) {
275276
return
276277
}
277278
getters[getterKey] = function wrappedGetter (state) {
278-
return rawGetter(getNestedState(state, modulePath))
279+
return rawGetter(getNestedState(state, modulePath), state)
279280
}
280281
})
281282
}

test/unit/test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,10 @@ describe('Vuex', () => {
368368
let calls = 0
369369
const makeAction = n => {
370370
return {
371-
[TEST] ({ state }) {
371+
[TEST] ({ state, rootState }) {
372372
calls++
373373
expect(state.a).to.equal(n)
374+
expect(rootState).to.equal(store.state)
374375
}
375376
}
376377
}
@@ -414,7 +415,12 @@ describe('Vuex', () => {
414415

415416
it('module: getters', function () {
416417
const makeGetter = n => ({
417-
[`getter${n}`]: state => state.a
418+
[`getter${n}`]: (state, rootState) => {
419+
if (rootState) {
420+
expect(rootState).to.equal(store.state)
421+
}
422+
return state.a
423+
}
418424
})
419425
const store = new Vuex.Store({
420426
state: {

0 commit comments

Comments
 (0)