diff --git a/circle.yml b/circle.yml index 807a2a68d..0834e36ef 100644 --- a/circle.yml +++ b/circle.yml @@ -1,3 +1,5 @@ machine: node: version: 5 + environment: + BABEL_ENV: development diff --git a/src/helpers.js b/src/helpers.js index fdd0eb2cf..82b16338e 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,9 +1,10 @@ -export function mapState (map) { +export function mapState (states) { const res = {} - Object.keys(map).forEach(key => { - const fn = map[key] + normalizeMap(states).forEach(({ key, val }) => { res[key] = function mappedState () { - return fn.call(this, this.$store.state, this.$store.getters) + return typeof val === 'function' + ? val.call(this, this.$store.state, this.$store.getters) + : this.$store.state[val] } }) return res diff --git a/test/unit/test.js b/test/unit/test.js index 23d0445b7..48900b7e5 100644 --- a/test/unit/test.js +++ b/test/unit/test.js @@ -225,7 +225,22 @@ describe('Vuex', () => { expect(child.$store).toBe(store) }) - it('helper: mapState', () => { + it('helper: mapState (array)', () => { + const store = new Vuex.Store({ + state: { + a: 1 + } + }) + const vm = new Vue({ + store, + computed: mapState(['a']) + }) + expect(vm.a).toBe(1) + store.state.a++ + expect(vm.a).toBe(2) + }) + + it('helper: mapState (object)', () => { const store = new Vuex.Store({ state: { a: 1