|
1 | 1 | /*! |
2 | | - * Vuex v0.6.3 |
| 2 | + * Vuex v0.7.0 |
3 | 3 | * (c) 2016 Evan You |
4 | 4 | * Released under the MIT License. |
5 | 5 | */ |
|
9 | 9 | (global.Vuex = factory()); |
10 | 10 | }(this, function () { 'use strict'; |
11 | 11 |
|
12 | | - var babelHelpers = {}; |
13 | | - babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
| 12 | + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
14 | 13 | return typeof obj; |
15 | 14 | } : function (obj) { |
16 | 15 | return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; |
17 | 16 | }; |
18 | 17 |
|
19 | | - babelHelpers.classCallCheck = function (instance, Constructor) { |
| 18 | + var classCallCheck = function (instance, Constructor) { |
20 | 19 | if (!(instance instanceof Constructor)) { |
21 | 20 | throw new TypeError("Cannot call a class as a function"); |
22 | 21 | } |
23 | 22 | }; |
24 | 23 |
|
25 | | - babelHelpers.createClass = function () { |
| 24 | + var createClass = function () { |
26 | 25 | function defineProperties(target, props) { |
27 | 26 | for (var i = 0; i < props.length; i++) { |
28 | 27 | var descriptor = props[i]; |
|
40 | 39 | }; |
41 | 40 | }(); |
42 | 41 |
|
43 | | - babelHelpers.toConsumableArray = function (arr) { |
| 42 | + var toConsumableArray = function (arr) { |
44 | 43 | if (Array.isArray(arr)) { |
45 | 44 | for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; |
46 | 45 |
|
|
50 | 49 | } |
51 | 50 | }; |
52 | 51 |
|
53 | | - babelHelpers; |
54 | | - |
55 | 52 | /** |
56 | 53 | * Merge an array of objects into one. |
57 | 54 | * |
|
89 | 86 | function deepClone(obj) { |
90 | 87 | if (Array.isArray(obj)) { |
91 | 88 | return obj.map(deepClone); |
92 | | - } else if (obj && (typeof obj === 'undefined' ? 'undefined' : babelHelpers.typeof(obj)) === 'object') { |
| 89 | + } else if (obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') { |
93 | 90 | var cloned = {}; |
94 | 91 | var keys = Object.keys(obj); |
95 | 92 | for (var i = 0, l = keys.length; i < l; i++) { |
|
110 | 107 | var Watcher = void 0; |
111 | 108 | function getWatcher(vm) { |
112 | 109 | if (!Watcher) { |
113 | | - var unwatch = vm.$watch('__vuex__', function (a) { |
114 | | - return a; |
115 | | - }); |
| 110 | + var noop = function noop() {}; |
| 111 | + var unwatch = vm.$watch(noop, noop); |
116 | 112 | Watcher = vm._watchers[0].constructor; |
117 | 113 | unwatch(); |
118 | 114 | } |
|
149 | 145 | }; |
150 | 146 |
|
151 | 147 | function override (Vue) { |
152 | | - // override init and inject vuex init procedure |
153 | | - var _init = Vue.prototype._init; |
154 | | - Vue.prototype._init = function () { |
155 | | - var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; |
156 | | - |
157 | | - options.init = options.init ? [vuexInit].concat(options.init) : vuexInit; |
158 | | - _init.call(this, options); |
159 | | - }; |
| 148 | + Vue.mixin({ init: init }); |
160 | 149 |
|
161 | 150 | /** |
162 | 151 | * Vuex init hook, injected into each instances init hooks list. |
163 | 152 | */ |
164 | 153 |
|
165 | | - function vuexInit() { |
| 154 | + function init() { |
166 | 155 | var options = this.$options; |
167 | 156 | var store = options.store; |
168 | 157 | var vuex = options.vuex; |
|
179 | 168 | console.warn('[vuex] store not injected. make sure to ' + 'provide the store option in your root component.'); |
180 | 169 | } |
181 | 170 | var state = vuex.state; |
182 | | - var getters = vuex.getters; |
183 | 171 | var actions = vuex.actions; |
| 172 | + var getters = vuex.getters; |
184 | 173 | // handle deprecated state option |
185 | 174 |
|
186 | 175 | if (state && !getters) { |
|
254 | 243 | var vm = store._vm; |
255 | 244 | var Watcher = getWatcher(vm); |
256 | 245 | var Dep = getDep(vm); |
257 | | - var watcher = new Watcher(vm, function (state) { |
258 | | - return getter(state); |
| 246 | + var watcher = new Watcher(vm, function (vm) { |
| 247 | + return getter(vm.state); |
259 | 248 | }, null, { lazy: true }); |
260 | 249 | var computedGetter = function computedGetter() { |
261 | 250 | if (watcher.dirty) { |
|
333 | 322 | var middlewares = _ref$middlewares === undefined ? [] : _ref$middlewares; |
334 | 323 | var _ref$strict = _ref.strict; |
335 | 324 | var strict = _ref$strict === undefined ? false : _ref$strict; |
336 | | - babelHelpers.classCallCheck(this, Store); |
| 325 | + classCallCheck(this, Store); |
337 | 326 |
|
338 | 327 | this._getterCacheId = 'vuex_store_' + uid++; |
339 | 328 | this._dispatching = false; |
|
357 | 346 | var silent = Vue.config.silent; |
358 | 347 | Vue.config.silent = true; |
359 | 348 | this._vm = new Vue({ |
360 | | - data: state |
| 349 | + data: { |
| 350 | + state: state |
| 351 | + } |
361 | 352 | }); |
362 | 353 | Vue.config.silent = silent; |
363 | 354 | this._setupModuleState(state, modules); |
|
376 | 367 | * @return {Object} |
377 | 368 | */ |
378 | 369 |
|
379 | | - babelHelpers.createClass(Store, [{ |
| 370 | + createClass(Store, [{ |
380 | 371 | key: 'dispatch', |
381 | 372 |
|
382 | 373 |
|
|
393 | 384 |
|
394 | 385 | var silent = false; |
395 | 386 | // compatibility for object actions, e.g. FSA |
396 | | - if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) { |
| 387 | + if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object' && type.type && arguments.length === 1) { |
397 | 388 | payload = [type.payload]; |
398 | 389 | if (type.silent) silent = true; |
399 | 390 | type = type.type; |
|
405 | 396 | // apply the mutation |
406 | 397 | if (Array.isArray(mutation)) { |
407 | 398 | mutation.forEach(function (m) { |
408 | | - return m.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload))); |
| 399 | + return m.apply(undefined, [state].concat(toConsumableArray(payload))); |
409 | 400 | }); |
410 | 401 | } else { |
411 | | - mutation.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload))); |
| 402 | + mutation.apply(undefined, [state].concat(toConsumableArray(payload))); |
412 | 403 | } |
413 | 404 | this._dispatching = false; |
414 | 405 | if (!silent) this._applyMiddlewares(type, payload); |
|
422 | 413 | * Same API as Vue's $watch, except when watching a function, |
423 | 414 | * the function gets the state as the first argument. |
424 | 415 | * |
425 | | - * @param {String|Function} expOrFn |
| 416 | + * @param {Function} fn |
426 | 417 | * @param {Function} cb |
427 | 418 | * @param {Object} [options] |
428 | 419 | */ |
429 | 420 |
|
430 | 421 | }, { |
431 | 422 | key: 'watch', |
432 | | - value: function watch(expOrFn, cb, options) { |
| 423 | + value: function watch(fn, cb, options) { |
433 | 424 | var _this2 = this; |
434 | 425 |
|
| 426 | + if (typeof fn !== 'function') { |
| 427 | + console.error('Vuex store.watch only accepts function.'); |
| 428 | + return; |
| 429 | + } |
435 | 430 | return this._vm.$watch(function () { |
436 | | - return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn); |
| 431 | + return fn(_this2.state); |
437 | 432 | }, cb, options); |
438 | 433 | } |
439 | 434 |
|
|
523 | 518 |
|
524 | 519 | var Watcher = getWatcher(this._vm); |
525 | 520 | /* eslint-disable no-new */ |
526 | | - new Watcher(this._vm, '$data', function () { |
| 521 | + new Watcher(this._vm, 'state', function () { |
527 | 522 | if (!_this3._dispatching) { |
528 | 523 | throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.'); |
529 | 524 | } |
|
596 | 591 | }, { |
597 | 592 | key: 'state', |
598 | 593 | get: function get() { |
599 | | - return this._vm._data; |
| 594 | + return this._vm.state; |
600 | 595 | }, |
601 | 596 | set: function set(v) { |
602 | 597 | throw new Error('[vuex] Vuex root state is read only.'); |
|
0 commit comments