Browse Source

state -> getters

Evan You 9 years ago
parent
commit
9d24f8fcf6

+ 1 - 1
examples/chat/components/MessageSection.vue

@@ -19,7 +19,7 @@ import { sendMessage } from '../vuex/actions'
 export default {
   components: { Message },
   vuex: {
-    state: {
+    getters: {
       thread ({ currentThreadID, threads }) {
         return currentThreadID ? threads[currentThreadID] : {}
       },

+ 1 - 1
examples/chat/components/Thread.vue

@@ -19,7 +19,7 @@ import { switchThread } from '../vuex/actions'
 export default {
   props: ['thread'],
   vuex: {
-    state: {
+    getters: {
       isCurrentThread ({ currentThreadID }) {
         return this.thread.id === currentThreadID
       }

+ 1 - 1
examples/chat/components/ThreadSection.vue

@@ -21,7 +21,7 @@ import Thread from './Thread.vue'
 export default {
   components: { Thread },
   vuex: {
-    state: {
+    getters: {
       threads: state => state.threads
     }
   },

+ 1 - 1
examples/counter/Counter.vue

@@ -13,7 +13,7 @@ import * as actions from './actions'
 
 export default {
   vuex: {
-    state: {
+    getters: {
       count: state => state.count
     },
     actions: actions

+ 1 - 1
examples/shopping-cart/components/Cart.vue

@@ -19,7 +19,7 @@ import { cartProducts } from '../vuex/getters'
 
 export default {
   vuex: {
-    state: {
+    getters: {
       products: cartProducts,
       checkoutStatus: ({ cart }) => cart.lastCheckout
     },

+ 1 - 1
examples/shopping-cart/components/ProductList.vue

@@ -17,7 +17,7 @@ import { getAllProducts, addToCart } from '../vuex/actions'
 
 export default {
   vuex: {
-    state: {
+    getters: {
       products: ({ products }) => products.all
     },
     actions: {

+ 1 - 1
examples/todomvc/components/App.vue

@@ -62,7 +62,7 @@ const filters = {
 export default {
   components: { Todo },
   vuex: {
-    state: {
+    getters: {
       todos: state => state.todos
     },
     actions: {

+ 12 - 5
src/override.js

@@ -20,13 +20,20 @@ export default function (Vue) {
           'provide the store option in your root component.'
         )
       }
-      const { state, actions } = vuex
-      // state
-      if (state) {
+      let { state, getters, actions } = vuex
+      // getters
+      if (state && !getters) {
+        console.warn(
+          '[vuex] vuex.state option has been deprecated. ' +
+          'Use vuex.getters instead.'
+        )
+        getters = state
+      }
+      if (getters) {
         options.computed = options.computed || {}
-        Object.keys(state).forEach(key => {
+        Object.keys(getters).forEach(key => {
           options.computed[key] = function vuexBoundGetter () {
-            return state[key].call(this, this.$store.state)
+            return getters[key].call(this, this.$store.state)
           }
         })
       }

+ 1 - 1
test/test.js

@@ -37,7 +37,7 @@ describe('Vuex', () => {
     const vm = new Vue({
       store,
       vuex: {
-        state: {
+        getters: {
           a: state => state.a
         },
         actions: {