|
1 | 1 | /**
|
2 |
| - * vuex v2.0.0-rc.4 |
| 2 | + * vuex v2.0.0-rc.5 |
3 | 3 | * (c) 2016 Evan You
|
4 | 4 | * @license MIT
|
5 | 5 | */
|
|
154 | 154 | this._wrappedGetters = Object.create(null)
|
155 | 155 | this._runtimeModules = Object.create(null)
|
156 | 156 | this._subscribers = []
|
157 |
| - this._pendingActions = [] |
| 157 | + this._watcherVM = new Vue() |
158 | 158 |
|
159 | 159 | // bind commit and dispatch to self
|
160 | 160 | var store = this
|
|
164 | 164 | this.dispatch = function boundDispatch (type, payload) {
|
165 | 165 | return dispatch.call(store, type, payload)
|
166 | 166 | }
|
167 |
| - this.commit = function boundCommit (type, payload) { |
168 |
| - return commit.call(store, type, payload) |
| 167 | + this.commit = function boundCommit (type, payload, options) { |
| 168 | + return commit.call(store, type, payload, options) |
169 | 169 | }
|
170 | 170 |
|
171 | 171 | // strict mode
|
|
194 | 194 | assert(false, "Use store.replaceState() to explicit replace store state.")
|
195 | 195 | };
|
196 | 196 |
|
197 |
| - Store.prototype.commit = function commit (type, payload) { |
| 197 | + Store.prototype.commit = function commit (type, payload, options) { |
198 | 198 | var this$1 = this;
|
199 | 199 |
|
200 | 200 | // check object-style commit
|
201 | 201 | var mutation
|
202 | 202 | if (isObject(type) && type.type) {
|
| 203 | + options = payload |
203 | 204 | payload = mutation = type
|
204 | 205 | type = type.type
|
205 | 206 | } else {
|
|
215 | 216 | handler(payload)
|
216 | 217 | })
|
217 | 218 | })
|
218 |
| - if (!payload || !payload.silent) { |
| 219 | + if (!options || !options.silent) { |
219 | 220 | this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); })
|
220 | 221 | }
|
221 | 222 | };
|
|
226 | 227 | console.error(("[vuex] unknown action type: " + type))
|
227 | 228 | return
|
228 | 229 | }
|
229 |
| - var res = entry.length > 1 |
| 230 | + return entry.length > 1 |
230 | 231 | ? Promise.all(entry.map(function (handler) { return handler(payload); }))
|
231 | 232 | : entry[0](payload)
|
232 |
| - var pending = this._pendingActions |
233 |
| - pending.push(res) |
234 |
| - return res.then(function (value) { |
235 |
| - pending.splice(pending.indexOf(res), 1) |
236 |
| - return value |
237 |
| - }) |
238 | 233 | };
|
239 | 234 |
|
240 | 235 | Store.prototype.subscribe = function subscribe (fn) {
|
|
254 | 249 | var this$1 = this;
|
255 | 250 |
|
256 | 251 | assert(typeof getter === 'function', "store.watch only accepts a function.")
|
257 |
| - return this._vm.$watch(function () { return getter(this$1.state); }, cb, options) |
| 252 | + return this._watcherVM.$watch(function () { return getter(this$1.state); }, cb, options) |
258 | 253 | };
|
259 | 254 |
|
260 | 255 | Store.prototype.replaceState = function replaceState (state) {
|
|
271 | 266 | this._runtimeModules[path.join('.')] = module
|
272 | 267 | installModule(this, this.state, path, module)
|
273 | 268 | // reset store to update getters...
|
274 |
| - resetStoreVM(this, this.state) |
275 |
| - }; |
| 269 | + resetStoreVM(this, this.state) |
| 270 | + }; |
276 | 271 |
|
277 | 272 | Store.prototype.unregisterModule = function unregisterModule (path) {
|
278 | 273 | var this$1 = this;
|
|
297 | 292 | }
|
298 | 293 | if (newOptions.getters) {
|
299 | 294 | options.getters = newOptions.getters
|
300 |
| - } |
301 |
| - if (newOptions.modules) { |
| 295 | + } |
| 296 | + if (newOptions.modules) { |
302 | 297 | for (var key in newOptions.modules) {
|
303 | 298 | options.modules[key] = newOptions.modules[key]
|
304 | 299 | }
|
305 | 300 | }
|
306 | 301 | resetStore(this)
|
307 | 302 | };
|
308 | 303 |
|
309 |
| - Store.prototype.onActionsResolved = function onActionsResolved (cb) { |
310 |
| - Promise.all(this._pendingActions).then(cb) |
311 |
| - }; |
312 |
| - |
313 | 304 | Store.prototype._withCommit = function _withCommit (fn) {
|
314 | 305 | var committing = this._committing
|
315 |
| - this._committing = true |
| 306 | + this._committing = true |
316 | 307 | fn()
|
317 | 308 | this._committing = committing
|
318 | 309 | };
|
|
0 commit comments