|
1 | 1 | /*! |
2 | | - * Vuex v0.6.1 |
| 2 | + * Vuex v0.6.2 |
3 | 3 | * (c) 2016 Evan You |
4 | 4 | * Released under the MIT License. |
5 | 5 | */ |
|
40 | 40 | }; |
41 | 41 | }(); |
42 | 42 |
|
| 43 | + babelHelpers.toConsumableArray = function (arr) { |
| 44 | + if (Array.isArray(arr)) { |
| 45 | + for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; |
| 46 | + |
| 47 | + return arr2; |
| 48 | + } else { |
| 49 | + return Array.from(arr); |
| 50 | + } |
| 51 | + }; |
| 52 | + |
43 | 53 | babelHelpers; |
44 | 54 |
|
45 | 55 | /** |
|
298 | 308 | // use a Vue instance to store the state tree |
299 | 309 | // suppress warnings just in case the user has added |
300 | 310 | // some funky global mixins |
| 311 | + if (!Vue) { |
| 312 | + throw new Error('[vuex] must call Vue.use(Vuex) before creating a store instance.'); |
| 313 | + } |
301 | 314 | var silent = Vue.config.silent; |
302 | 315 | Vue.config.silent = true; |
303 | 316 | this._vm = new Vue({ |
|
337 | 350 | payload[_key2 - 1] = arguments[_key2]; |
338 | 351 | } |
339 | 352 |
|
| 353 | + // compatibility for object actions, e.g. FSA |
| 354 | + if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) { |
| 355 | + payload = [type]; |
| 356 | + type = type.type; |
| 357 | + } |
340 | 358 | var mutation = this._mutations[type]; |
341 | 359 | var prevSnapshot = this._prevSnapshot; |
342 | 360 | var state = this.state; |
|
347 | 365 | // apply the mutation |
348 | 366 | if (Array.isArray(mutation)) { |
349 | 367 | mutation.forEach(function (m) { |
350 | | - return m.apply(undefined, [state].concat(payload)); |
| 368 | + return m.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload))); |
351 | 369 | }); |
352 | 370 | } else { |
353 | | - mutation.apply(undefined, [state].concat(payload)); |
| 371 | + mutation.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload))); |
354 | 372 | } |
355 | 373 | this._dispatching = false; |
356 | 374 | // invoke middlewares |
|
393 | 411 | } |
394 | 412 |
|
395 | 413 | /** |
396 | | - * Hot update actions and mutations. |
| 414 | + * Hot update mutations & modules. |
397 | 415 | * |
398 | 416 | * @param {Object} options |
399 | 417 | * - {Object} [mutations] |
|
433 | 451 | * Bind mutations for each module to its sub tree and |
434 | 452 | * merge them all into one final mutations map. |
435 | 453 | * |
436 | | - * @param {Object} modules |
| 454 | + * @param {Object} updatedModules |
437 | 455 | */ |
438 | 456 |
|
439 | 457 | }, { |
440 | 458 | key: '_setupModuleMutations', |
441 | | - value: function _setupModuleMutations(modules) { |
442 | | - this._modules = modules; |
| 459 | + value: function _setupModuleMutations(updatedModules) { |
| 460 | + var modules = this._modules; |
443 | 461 | var getPath = Vue.parsers.path.getPath; |
444 | 462 |
|
445 | 463 | var allMutations = [this._rootMutations]; |
| 464 | + Object.keys(updatedModules).forEach(function (key) { |
| 465 | + modules[key] = updatedModules[key]; |
| 466 | + }); |
446 | 467 | Object.keys(modules).forEach(function (key) { |
447 | 468 | var module = modules[key]; |
448 | 469 | if (!module || !module.mutations) return; |
|
535 | 556 | override(Vue); |
536 | 557 | } |
537 | 558 |
|
| 559 | + // auto install in dist mode |
| 560 | + if (typeof window !== 'undefined' && window.Vue) { |
| 561 | + install(window.Vue); |
| 562 | + } |
| 563 | + |
538 | 564 | function createLogger() { |
539 | 565 | console.warn('[vuex] Vuex.createLogger has been deprecated.' + 'Use `import createLogger from \'vuex/logger\' instead.'); |
540 | 566 | } |
|
0 commit comments