From 33399f1b782bd1da20d7a7012513faf1e4c0b4da Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 21 Jun 2016 04:05:52 -0400 Subject: [PATCH] [build] 0.7.0 --- dist/vuex.js | 65 ++++++++++++++++++++++-------------------------- dist/vuex.min.js | 4 +-- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/dist/vuex.js b/dist/vuex.js index cd14f9ead..496409027 100644 --- a/dist/vuex.js +++ b/dist/vuex.js @@ -1,5 +1,5 @@ /*! - * Vuex v0.6.3 + * Vuex v0.7.0 * (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(); } @@ -149,20 +145,13 @@ }; 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]; - - options.init = options.init ? [vuexInit].concat(options.init) : vuexInit; - _init.call(this, options); - }; + Vue.mixin({ init: init }); /** * Vuex init hook, injected into each instances init hooks list. */ - function vuexInit() { + function init() { var options = this.$options; var store = options.store; var vuex = options.vuex; @@ -179,8 +168,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 +243,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 +322,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 +346,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 +367,7 @@ * @return {Object} */ - babelHelpers.createClass(Store, [{ + createClass(Store, [{ key: 'dispatch', @@ -393,7 +384,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 +396,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 +413,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 +518,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 +591,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.'); diff --git a/dist/vuex.min.js b/dist/vuex.min.js index fe8a615c1..57b6598ed 100644 --- a/dist/vuex.min.js +++ b/dist/vuex.min.js @@ -1,6 +1,6 @@ /*! - * Vuex v0.6.3 + * Vuex v0.7.0 * (c) 2016 Evan You * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Vuex=e()}(this,function(){"use strict";function t(t){return t.reduce(function(t,e){return Object.keys(e).forEach(function(n){var o=t[n];o?Array.isArray(o)?o.push(e[n]):t[n]=[t[n],e[n]]:t[n]=e[n]}),t},{})}function e(t){if(Array.isArray(t))return t.map(e);if(t&&"object"===("undefined"==typeof t?"undefined":s["typeof"](t))){for(var n={},o=Object.keys(t),i=0,r=o.length;r>i;i++){var a=o[i];n[a]=e(t[a])}return n}return t}function n(t){if(!u){var e=t.$watch("__vuex__",function(t){return t});u=t._watchers[0].constructor,e()}return u}function o(t){return c||(c=t._data.__ob__.dep.constructor),c}function i(t){function e(){var t=this.$options,e=t.store,n=t.vuex;if(e?this.$store=e:t.parent&&t.parent.$store&&(this.$store=t.parent.$store),n){this.$store||console.warn("[vuex] store not injected. make sure to provide the store option in your root component.");var o=n.state,i=n.getters,a=n.actions;if(o&&!i&&(console.warn("[vuex] vuex.state option will been deprecated in 1.0. Use vuex.getters instead."),i=o),i){t.computed=t.computed||{};for(var u in i)r(this,u,i[u])}if(a){t.methods=t.methods||{};for(var c in a)t.methods[c]=s(this.$store,a[c],c)}}}function i(){throw new Error("vuex getter properties are read-only.")}function r(t,e,n){"function"!=typeof n?console.warn("[vuex] Getter bound to key 'vuex.getters."+e+"' is not a function."):Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:a(t.$store,n),set:i})}function a(t,e){var i=t._getterCacheId;if(e[i])return e[i];var r=t._vm,a=n(r),s=o(r),u=new a(r,function(t){return e(t)},null,{lazy:!0}),c=function(){return u.dirty&&u.evaluate(),s.target&&u.depend(),u.value};return e[i]=c,c}function s(t,e,n){return"function"!=typeof e&&console.warn("[vuex] Action bound to key 'vuex.actions."+n+"' is not a function."),function(){for(var n=arguments.length,o=Array(n),i=0;n>i;i++)o[i]=arguments[i];return e.call.apply(e,[this,t].concat(o))}}var u=t.prototype._init;t.prototype._init=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];t.init=t.init?[e].concat(t.init):e,u.call(this,t)};var c=t.config.optionMergeStrategies.computed;t.config.optionMergeStrategies.vuex=function(t,e){return t?e?{getters:c(t.getters,e.getters),state:c(t.state,e.state),actions:c(t.actions,e.actions)}:t:e}}function r(t){return h?void console.warn("[vuex] already installed. Vue.use(Vuex) should be called only once."):(h=t,void i(h))}function a(){console.warn("[vuex] Vuex.createLogger has been deprecated.Use `import createLogger from 'vuex/logger' instead.")}var s={};s["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},s.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},s.createClass=function(){function t(t,e){for(var n=0;no;o++)n[o]=arguments[o];y.apply(t,n)},!h)throw new Error("[vuex] must call Vue.use(Vuex) before creating a store instance.");var _=h.config.silent;h.config.silent=!0,this._vm=new h({data:i}),h.config.silent=_,this._setupModuleState(i,c),this._setupModuleMutations(c),this._setupMiddlewares(d,i),v&&this._setupMutationCheck()}return s.createClass(o,[{key:"dispatch",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;e>o;o++)n[o-1]=arguments[o];var i=!1;"object"===("undefined"==typeof t?"undefined":s["typeof"](t))&&t.type&&1===arguments.length&&(n=[t.payload],t.silent&&(i=!0),t=t.type);var r=this._mutations[t],a=this.state;r?(this._dispatching=!0,Array.isArray(r)?r.forEach(function(t){return t.apply(void 0,[a].concat(s.toConsumableArray(n)))}):r.apply(void 0,[a].concat(s.toConsumableArray(n))),this._dispatching=!1,i||this._applyMiddlewares(t,n)):console.warn("[vuex] Unknown mutation: "+t)}},{key:"watch",value:function(t,e,n){var o=this;return this._vm.$watch(function(){return"function"==typeof t?t(o.state):o._vm.$get(t)},e,n)}},{key:"hotUpdate",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.mutations,n=t.modules;this._rootMutations=this._mutations=e||this._rootMutations,this._setupModuleMutations(n||this._modules)}},{key:"_setupModuleState",value:function(t,e){Object.keys(e).forEach(function(n){h.set(t,n,e[n].state||{})})}},{key:"_setupModuleMutations",value:function(e){var n=this._modules,o=[this._rootMutations];Object.keys(e).forEach(function(t){n[t]=e[t]}),Object.keys(n).forEach(function(t){var e=n[t];if(e&&e.mutations){var i={};Object.keys(e.mutations).forEach(function(n){var o=e.mutations[n];i[n]=function(e){for(var n=arguments.length,i=Array(n>1?n-1:0),r=1;n>r;r++)i[r-1]=arguments[r];o.apply(void 0,[e[t]].concat(i))}}),o.push(i)}}),this._mutations=t(o)}},{key:"_setupMutationCheck",value:function(){var t=this,e=n(this._vm);new e(this._vm,"$data",function(){if(!t._dispatching)throw new Error("[vuex] Do not mutate vuex store state outside mutation handlers.")},{deep:!0,sync:!0})}},{key:"_setupMiddlewares",value:function(t,n){var o=this;this._middlewares=[d].concat(t),this._needSnapshots=t.some(function(t){return t.snapshot}),this._needSnapshots&&console.log("[vuex] One or more of your middlewares are taking state snapshots for each mutation. Make sure to use them only during development.");var i=this._prevSnapshot=this._needSnapshots?e(n):null;this._middlewares.forEach(function(t){t.onInit&&t.onInit(t.snapshot?i:n,o)})}},{key:"_applyMiddlewares",value:function(t,n){var o=this,i=this.state,r=this._prevSnapshot,a=void 0,s=void 0;this._needSnapshots&&(a=this._prevSnapshot=e(i),s=e(n)),this._middlewares.forEach(function(e){e.onMutation&&(e.snapshot?e.onMutation({type:t,payload:s},a,r,o):e.onMutation({type:t,payload:n},i,o))})}},{key:"state",get:function(){return this._vm._data},set:function(t){throw new Error("[vuex] Vuex root state is read only.")}}]),o}();"undefined"!=typeof window&&window.Vue&&r(window.Vue);var v={Store:p,install:r,createLogger:a};return v}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Vuex=e()}(this,function(){"use strict";function t(t){return t.reduce(function(t,e){return Object.keys(e).forEach(function(n){var o=t[n];o?Array.isArray(o)?o.push(e[n]):t[n]=[t[n],e[n]]:t[n]=e[n]}),t},{})}function e(t){if(Array.isArray(t))return t.map(e);if(t&&"object"===("undefined"==typeof t?"undefined":s(t))){for(var n={},o=Object.keys(t),i=0,r=o.length;i1?e-1:0),o=1;o1?n-1:0),r=1;r