8000 test wip · vuejs/v2.vuejs.org@c9706ee · GitHub
[go: up one dir, main page]

Skip to content

Commit c9706ee

Browse files
committed
test wip
1 parent 6b6d4be commit c9706ee

File tree

4 files changed

+455
- 8000 338
lines changed

4 files changed

+455
-338
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"chat": "cd examples/chat && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
1717
"build": "node build/build.js",
1818
"build-examples": "BABEL_ENV=development webpack --config examples/webpack.build-all.config.js",
19-
"unit": "BABEL_ENV=development mocha test/unit/test.js --compilers js:babel-core/register",
19+
"unit": "BABEL_ENV=development mocha test/unit/test.js --compilers js:babel-core/register 2>/dev/null",
2020
"pree2e": "npm run build-examples",
2121
"e2e": "casperjs test --concise ./test/e2e",
2222
"test": "eslint src && npm run unit && npm run e2e",

src/helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ export function mapGetters (getters) {
22
const res = {}
33
normalizeMap(getters).forEach(({ key, val }) => {
44
res[key] = function mappedGetter () {
5+
if (!(val in this.$store.getters)) {
6+
console.error(`[vuex] unknown getter: ${val}`)
7+
}
58
return this.$store.getters[val]
69
}
710
})

src/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class Store {
3636
const store = this
3737
const { dispatch, commit } = this
3838
this.dispatch = function boundDispatch (type, payload) {
39-
dispatch.call(store, type, payload)
39+
return dispatch.call(store, type, payload)
4040
}
4141
this.commit = function boundCommit (type, payload) {
42-
commit.call(store, type, payload)
42+
return commit.call(store, type, payload)
4343
}
4444

4545
// init state and getters
@@ -140,24 +140,27 @@ class Store {
140140
}
141141

142142
commit (type, payload) {
143-
const entry = this._mutations[type]
144-
if (!entry) {
145-
console.error(`[vuex] unknown mutation type: ${type}`)
146-
return
147-
}
148143
// check object-style commit
149144
let mutation
150-
if (isObject(type)) {
145+
if (isObject(type) && type.type) {
151146
payload = mutation = type
147+
type = type.type
152148
} else {
153149
mutation = { type, payload }
154150
}
151+
const entry = this._mutations[type]
152+
if (!entry) {
153+
console.error(`[vuex] unknown mutation type: ${type}`)
154+
return
155+
}
155156
this._committing = true
156157
entry.forEach(function commitIterator (handler) {
157158
handler(payload)
< A070 /code>
158159
})
159160
this._committing = false
160-
this._subscribers.forEach(sub => sub(mutation, this.state))
161+
if (!payload || !payload.silent) {
162+
this._subscribers.forEach(sub => sub(mutation, this.state))
163+
}
161164
}
162165

163166
dispatch (type, payload) {
@@ -169,7 +172,7 @@ class Store {
169172
}
170173
return entry.length > 1
171174
? Promise.all(entry.map(handler => handler(payload)))
172-
: Promise.resolve(entry[0](payload))
175+
: entry[0](payload)
173176
}
174177

175178
subscribe (fn) {

0 commit comments

Comments
 (0)
0