فهرست منبع

Enable "state" as a valid key in getters (#452)

* enable 'state' to be a valid key in getters

* do not checking `dist`
Max 8 سال پیش
والد
کامیت
7141fb0aee
2فایلهای تغییر یافته به همراه8 افزوده شده و 8 حذف شده
  1. 1 1
      src/index.js
  2. 7 7
      test/unit/test.js

+ 1 - 1
src/index.js

@@ -53,7 +53,7 @@ class Store {
   }
   }
 
 
   get state () {
   get state () {
-    return this._vm.state
+    return this._vm.$data.state
   }
   }
 
 
   set state (v) {
   set state (v) {

+ 7 - 7
test/unit/test.js

@@ -173,10 +173,10 @@ describe('Vuex', () => {
   it('getters', () => {
   it('getters', () => {
     const store = new Vuex.Store({
     const store = new Vuex.Store({
       state: {
       state: {
-        a: 1
+        a: 0
       },
       },
       getters: {
       getters: {
-        hasAny: state => state.a > 1
+        state: state => state.a > 0 ? 'hasAny' : 'none'
       },
       },
       mutations: {
       mutations: {
         [TEST] (state, n) {
         [TEST] (state, n) {
@@ -186,17 +186,17 @@ describe('Vuex', () => {
       actions: {
       actions: {
         check ({ getters }, value) {
         check ({ getters }, value) {
           // check for exposing getters into actions
           // check for exposing getters into actions
-          expect(getters.hasAny).toBe(value)
+          expect(getters.state).toBe(value)
         }
         }
       }
       }
     })
     })
-    expect(store.getters.hasAny).toBe(false)
-    store.dispatch('check', false)
+    expect(store.getters.state).toBe('none')
+    store.dispatch('check', 'none')
 
 
     store.commit(TEST, 1)
     store.commit(TEST, 1)
 
 
-    expect(store.getters.hasAny).toBe(true)
-    store.dispatch('check', true)
+    expect(store.getters.state).toBe('hasAny')
+    store.dispatch('check', 'hasAny')
   })
   })
 
 
   it('dynamic module registration', () => {
   it('dynamic module registration', () => {