Skip to content

Commit 9d24f8f

Browse files
committed
state -> getters
1 parent cc8730d commit 9d24f8f

File tree

9 files changed

+20
-13
lines changed

9 files changed

+20
-13
lines changed

examples/chat/components/MessageSection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { sendMessage } from '../vuex/actions'
1919
export default {
2020
components: { Message },
2121
vuex: {
22-
state: {
22+
getters: {
2323
thread ({ currentThreadID, threads }) {
2424
return currentThreadID ? threads[currentThreadID] : {}
2525
},

examples/chat/components/Thread.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { switchThread } from '../vuex/actions'
1919
export default {
2020
props: ['thread'],
2121
vuex: {
22-
state: {
22+
getters: {
2323
isCurrentThread ({ currentThreadID }) {
2424
return this.thread.id === currentThreadID
2525
}

examples/chat/components/ThreadSection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Thread from './Thread.vue'
2121
export default {
2222
components: { Thread },
2323
vuex: {
24-
state: {
24+
getters: {
2525
threads: state => state.threads
2626
}
2727
},

examples/counter/Counter.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as actions from './actions'
1313
1414
export default {
1515
vuex: {
16-
state: {
16+
getters: {
1717
count: state => state.count
1818
},
1919
actions: actions

examples/shopping-cart/components/Cart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { cartProducts } from '../vuex/getters'
1919
2020
export default {
2121
vuex: {
22-
state: {
22+
getters: {
2323
products: cartProducts,
2424
checkoutStatus: ({ cart }) => cart.lastCheckout
2525
},

examples/shopping-cart/components/ProductList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getAllProducts, addToCart } from '../vuex/actions'
1717
1818
export default {
1919
vuex: {
20-
state: {
20+
getters: {
2121
products: ({ products }) => products.all
2222
},
2323
actions: {

examples/todomvc/components/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const filters = {
6262
export default {
6363
components: { Todo },
6464
vuex: {
65-
state: {
65+
getters: {
6666
todos: state => state.todos
6767
},
6868
actions: {

src/override.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ export default function (Vue) {
2020
'provide the store option in your root component.'
2121
)
2222
}
23-
const { state, actions } = vuex
24-
// state
25-
if (state) {
23+
let { state, getters, actions } = vuex
24+
// getters
25+
if (state && !getters) {
26+
console.warn(
27+
'[vuex] vuex.state option has been deprecated. ' +
28+
'Use vuex.getters instead.'
29+
)
30+
getters = state
31+
}
32+
if (getters) {
2633
options.computed = options.computed || {}
27-
Object.keys(state).forEach(key => {
34+
Object.keys(getters).forEach(key => {
2835
options.computed[key] = function vuexBoundGetter () {
29-
return state[key].call(this, this.$store.state)
36+
return getters[key].call(this, this.$store.state)
3037
}
3138
})
3239
}

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Vuex', () => {
3737
const vm = new Vue({
3838
store,
3939
vuex: {
40-
state: {
40+
getters: {
4141
a: state => state.a
4242
},
4343
actions: {

0 commit comments

Comments
 (0)