|
@@ -1,5 +1,5 @@
|
|
|
/*!
|
|
|
- * Vuex v0.6.3
|
|
|
+ * Vuex v0.8.2
|
|
|
* (c) 2016 Evan You
|
|
|
* Released under the MIT License.
|
|
|
*/
|
|
@@ -9,20 +9,19 @@
|
|
|
(global.Vuex = factory());
|
|
|
}(this, function () { 'use strict';
|
|
|
|
|
|
- var babelHelpers = {};
|
|
|
- babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
|
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
|
return typeof obj;
|
|
|
} : function (obj) {
|
|
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
|
};
|
|
|
|
|
|
- babelHelpers.classCallCheck = function (instance, Constructor) {
|
|
|
+ var classCallCheck = function (instance, Constructor) {
|
|
|
if (!(instance instanceof Constructor)) {
|
|
|
throw new TypeError("Cannot call a class as a function");
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- babelHelpers.createClass = function () {
|
|
|
+ var createClass = function () {
|
|
|
function defineProperties(target, props) {
|
|
|
for (var i = 0; i < props.length; i++) {
|
|
|
var descriptor = props[i];
|
|
@@ -40,7 +39,7 @@
|
|
|
};
|
|
|
}();
|
|
|
|
|
|
- babelHelpers.toConsumableArray = function (arr) {
|
|
|
+ var toConsumableArray = function (arr) {
|
|
|
if (Array.isArray(arr)) {
|
|
|
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
|
|
|
@@ -50,8 +49,6 @@
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- babelHelpers;
|
|
|
-
|
|
|
/**
|
|
|
* Merge an array of objects into one.
|
|
|
*
|
|
@@ -89,7 +86,7 @@
|
|
|
function deepClone(obj) {
|
|
|
if (Array.isArray(obj)) {
|
|
|
return obj.map(deepClone);
|
|
|
- } else if (obj && (typeof obj === 'undefined' ? 'undefined' : babelHelpers.typeof(obj)) === 'object') {
|
|
|
+ } else if (obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
|
|
|
var cloned = {};
|
|
|
var keys = Object.keys(obj);
|
|
|
for (var i = 0, l = keys.length; i < l; i++) {
|
|
@@ -110,9 +107,8 @@
|
|
|
var Watcher = void 0;
|
|
|
function getWatcher(vm) {
|
|
|
if (!Watcher) {
|
|
|
- var unwatch = vm.$watch('__vuex__', function (a) {
|
|
|
- return a;
|
|
|
- });
|
|
|
+ var noop = function noop() {};
|
|
|
+ var unwatch = vm.$watch(noop, noop);
|
|
|
Watcher = vm._watchers[0].constructor;
|
|
|
unwatch();
|
|
|
}
|
|
@@ -134,11 +130,8 @@
|
|
|
if (!hook) return;
|
|
|
hook.emit('vuex:init', store);
|
|
|
hook.on('vuex:travel-to-state', function (targetState) {
|
|
|
- var currentState = store._vm._data;
|
|
|
store._dispatching = true;
|
|
|
- Object.keys(targetState).forEach(function (key) {
|
|
|
- currentState[key] = targetState[key];
|
|
|
- });
|
|
|
+ store._vm.state = targetState;
|
|
|
store._dispatching = false;
|
|
|
});
|
|
|
},
|
|
@@ -149,14 +142,24 @@
|
|
|
};
|
|
|
|
|
|
function override (Vue) {
|
|
|
- // override init and inject vuex init procedure
|
|
|
- var _init = Vue.prototype._init;
|
|
|
- Vue.prototype._init = function () {
|
|
|
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
|
|
+ var version = Number(Vue.version.split('.')[0]);
|
|
|
|
|
|
- options.init = options.init ? [vuexInit].concat(options.init) : vuexInit;
|
|
|
- _init.call(this, options);
|
|
|
- };
|
|
|
+ if (version >= 2) {
|
|
|
+ var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1;
|
|
|
+ Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit });
|
|
|
+ } else {
|
|
|
+ (function () {
|
|
|
+ // override init and inject vuex init procedure
|
|
|
+ // for 1.x backwards compatibility.
|
|
|
+ var _init = Vue.prototype._init;
|
|
|
+ Vue.prototype._init = function () {
|
|
|
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
|
|
+
|
|
|
+ options.init = options.init ? [vuexInit].concat(options.init) : vuexInit;
|
|
|
+ _init.call(this, options);
|
|
|
+ };
|
|
|
+ })();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Vuex init hook, injected into each instances init hooks list.
|
|
@@ -179,8 +182,8 @@
|
|
|
console.warn('[vuex] store not injected. make sure to ' + 'provide the store option in your root component.');
|
|
|
}
|
|
|
var state = vuex.state;
|
|
|
- var getters = vuex.getters;
|
|
|
var actions = vuex.actions;
|
|
|
+ var getters = vuex.getters;
|
|
|
// handle deprecated state option
|
|
|
|
|
|
if (state && !getters) {
|
|
@@ -254,8 +257,8 @@
|
|
|
var vm = store._vm;
|
|
|
var Watcher = getWatcher(vm);
|
|
|
var Dep = getDep(vm);
|
|
|
- var watcher = new Watcher(vm, function (state) {
|
|
|
- return getter(state);
|
|
|
+ var watcher = new Watcher(vm, function (vm) {
|
|
|
+ return getter(vm.state);
|
|
|
}, null, { lazy: true });
|
|
|
var computedGetter = function computedGetter() {
|
|
|
if (watcher.dirty) {
|
|
@@ -333,7 +336,7 @@
|
|
|
var middlewares = _ref$middlewares === undefined ? [] : _ref$middlewares;
|
|
|
var _ref$strict = _ref.strict;
|
|
|
var strict = _ref$strict === undefined ? false : _ref$strict;
|
|
|
- babelHelpers.classCallCheck(this, Store);
|
|
|
+ classCallCheck(this, Store);
|
|
|
|
|
|
this._getterCacheId = 'vuex_store_' + uid++;
|
|
|
this._dispatching = false;
|
|
@@ -357,7 +360,9 @@
|
|
|
var silent = Vue.config.silent;
|
|
|
Vue.config.silent = true;
|
|
|
this._vm = new Vue({
|
|
|
- data: state
|
|
|
+ data: {
|
|
|
+ state: state
|
|
|
+ }
|
|
|
});
|
|
|
Vue.config.silent = silent;
|
|
|
this._setupModuleState(state, modules);
|
|
@@ -376,7 +381,7 @@
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
|
|
|
- babelHelpers.createClass(Store, [{
|
|
|
+ createClass(Store, [{
|
|
|
key: 'dispatch',
|
|
|
|
|
|
|
|
@@ -393,7 +398,7 @@
|
|
|
|
|
|
var silent = false;
|
|
|
// compatibility for object actions, e.g. FSA
|
|
|
- if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) {
|
|
|
+ if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object' && type.type && arguments.length === 1) {
|
|
|
payload = [type.payload];
|
|
|
if (type.silent) silent = true;
|
|
|
type = type.type;
|
|
@@ -405,10 +410,10 @@
|
|
|
// apply the mutation
|
|
|
if (Array.isArray(mutation)) {
|
|
|
mutation.forEach(function (m) {
|
|
|
- return m.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload)));
|
|
|
+ return m.apply(undefined, [state].concat(toConsumableArray(payload)));
|
|
|
});
|
|
|
} else {
|
|
|
- mutation.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload)));
|
|
|
+ mutation.apply(undefined, [state].concat(toConsumableArray(payload)));
|
|
|
}
|
|
|
this._dispatching = false;
|
|
|
if (!silent) this._applyMiddlewares(type, payload);
|
|
@@ -422,18 +427,22 @@
|
|
|
* Same API as Vue's $watch, except when watching a function,
|
|
|
* the function gets the state as the first argument.
|
|
|
*
|
|
|
- * @param {String|Function} expOrFn
|
|
|
+ * @param {Function} fn
|
|
|
* @param {Function} cb
|
|
|
* @param {Object} [options]
|
|
|
*/
|
|
|
|
|
|
}, {
|
|
|
key: 'watch',
|
|
|
- value: function watch(expOrFn, cb, options) {
|
|
|
+ value: function watch(fn, cb, options) {
|
|
|
var _this2 = this;
|
|
|
|
|
|
+ if (typeof fn !== 'function') {
|
|
|
+ console.error('Vuex store.watch only accepts function.');
|
|
|
+ return;
|
|
|
+ }
|
|
|
return this._vm.$watch(function () {
|
|
|
- return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn);
|
|
|
+ return fn(_this2.state);
|
|
|
}, cb, options);
|
|
|
}
|
|
|
|
|
@@ -523,7 +532,7 @@
|
|
|
|
|
|
var Watcher = getWatcher(this._vm);
|
|
|
/* eslint-disable no-new */
|
|
|
- new Watcher(this._vm, '$data', function () {
|
|
|
+ new Watcher(this._vm, 'state', function () {
|
|
|
if (!_this3._dispatching) {
|
|
|
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');
|
|
|
}
|
|
@@ -596,7 +605,7 @@
|
|
|
}, {
|
|
|
key: 'state',
|
|
|
get: function get() {
|
|
|
- return this._vm._data;
|
|
|
+ return this._vm.state;
|
|
|
},
|
|
|
set: function set(v) {
|
|
|
throw new Error('[vuex] Vuex root state is read only.');
|
|
@@ -619,14 +628,9 @@
|
|
|
install(window.Vue);
|
|
|
}
|
|
|
|
|
|
- function createLogger() {
|
|
|
- console.warn('[vuex] Vuex.createLogger has been deprecated.' + 'Use `import createLogger from \'vuex/logger\' instead.');
|
|
|
- }
|
|
|
-
|
|
|
var index = {
|
|
|
Store: Store,
|
|
|
- install: install,
|
|
|
- createLogger: createLogger
|
|
|
+ install: install
|
|
|
};
|
|
|
|
|
|
return index;
|