From d01ded1590d37913395ffab7f9f3ed1abfd77ea8 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Thu, 28 Jul 2016 14:54:57 -0400 Subject: [PATCH 1/2] support array syntax for mapState --- src/helpers.js | 9 +++++---- test/unit/test.js | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) 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 From 4d76bee1696e8883257369dc8d567ce395f03c88 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Sat, 30 Jul 2016 02:37:26 -0400 Subject: [PATCH 2/2] fix tests for PRs on circle ci --- circle.yml | 2 ++ 1 file changed, 2 insertions(+) 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