Skip to content

Commit 7141fb0

Browse files
xiaoyanhaoyyx990803
authored andcommitted
Enable "state" as a valid key in getters (#452)
* enable 'state' to be a valid key in getters * do not checking `dist`
1 parent 7cf03d3 commit 7141fb0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Store {
5353
}
5454

5555
get state () {
56-
return this._vm.state
56+
return this._vm.$data.state
5757
}
5858

5959
set state (v) {

test/unit/test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ describe('Vuex', () => {
173173
it('getters', () => {
174174
const store = new Vuex.Store({
175175
state: {
176-
a: 1
176+
a: 0
177177
},
178178
getters: {
179-
hasAny: state => state.a > 1
179+
state: state => state.a > 0 ? 'hasAny' : 'none'
180180
},
181181
mutations: {
182182
[TEST] (state, n) {
@@ -186,17 +186,17 @@ describe('Vuex', () => {
186186
actions: {
187187
check ({ getters }, value) {
188188
// check for exposing getters into actions
189-
expect(getters.hasAny).toBe(value)
189+
expect(getters.state).toBe(value)
190190
}
191191
}
192192
})
193-
expect(store.getters.hasAny).toBe(false)
194-
store.dispatch('check', false)
193+
expect(store.getters.state).toBe('none')
194+
store.dispatch('check', 'none')
195195

196196
store.commit(TEST, 1)
197197

198-
expect(store.getters.hasAny).toBe(true)
199-
store.dispatch('check', true)
198+
expect(store.getters.state).toBe('hasAny')
199+
store.dispatch('check', 'hasAny')
200200
})
201201

202202
it('dynamic module registration', () => {

0 commit comments

Comments
 (0)