Skip to content

Commit 870bdc5

Browse files
committed
also expose getters in mapState
1 parent abce7b0 commit 870bdc5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export function mapState (map) {
33
Object.keys(map).forEach(key => {
44
const fn = map[key]
55
res[key] = function mappedState () {
6-
return fn.call(this, this.$store.state)
6+
return fn.call(this, this.$store.state, this.$store.getters)
77
}
88
})
99
return res

test/unit/test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,22 @@ describe('Vuex', () => {
229229
const store = new Vuex.Store({
230230
state: {
231231
a: 1
232+
},
233+
getters: {
234+
b: () => 2
232235
}
233236
})
234237
const vm = new Vue({
235238
store,
236239
computed: mapState({
237-
a: state => state.a + 1
240+
a: (state, getters) => {
241+
return state.a + getters.b
242+
}
238243
})
239244
})
240-
expect(vm.a).to.equal(2)
241-
store.state.a++
242245
expect(vm.a).to.equal(3)
246+
store.state.a++
247+
expect(vm.a).to.equal(4)
243248
})
244249

245250
it('helper: mapMutations (array)', () => {

0 commit comments

Comments
 (0)