vuex.min.js 6.9 KB

123456
  1. /*!
  2. * Vuex v0.7.0
  3. * (c) 2016 Evan You
  4. * Released under the MIT License.
  5. */
  6. !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;i<r;i++){var a=o[i];n[a]=e(t[a])}return n}return t}function n(t){if(!d){var e=function(){},n=t.$watch(e,e);d=t._watchers[0].constructor,n()}return d}function o(t){return h||(h=t._data.__ob__.dep.constructor),h}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.actions,a=n.getters;if(o&&!a&&(console.warn("[vuex] vuex.state option will been deprecated in 1.0. Use vuex.getters instead."),a=o),a){t.computed=t.computed||{};for(var u in a)r(this,u,a[u])}if(i){t.methods=t.methods||{};for(var c in i)t.methods[c]=s(this.$store,i[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.state)},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;i<n;i++)o[i]=arguments[i];return e.call.apply(e,[this,t].concat(o))}}t.mixin({init:e});var u=t.config.optionMergeStrategies.computed;t.config.optionMergeStrategies.vuex=function(t,e){return t?e?{getters:u(t.getters,e.getters),state:u(t.state,e.state),actions:u(t.actions,e.actions)}:t:e}}function r(t){return v?void console.warn("[vuex] already installed. Vue.use(Vuex) should be called only once."):(v=t,void i(v))}function a(){console.warn("[vuex] Vuex.createLogger has been deprecated.Use `import createLogger from 'vuex/logger' instead.")}var s="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},u=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},c=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),f=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},d=void 0,h=void 0,l="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,p={onInit:function(t,e){l&&(l.emit("vuex:init",e),l.on("vuex:travel-to-state",function(t){var n=e._vm._data;e._dispatching=!0,Object.keys(t).forEach(function(e){n[e]=t[e]}),e._dispatching=!1}))},onMutation:function(t,e){l&&l.emit("vuex:mutation",t,e)}},v=void 0,y=0,m=function(){function o(){var t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.state,i=void 0===n?{}:n,r=e.mutations,a=void 0===r?{}:r,s=e.modules,c=void 0===s?{}:s,f=e.middlewares,d=void 0===f?[]:f,h=e.strict,l=void 0!==h&&h;u(this,o),this._getterCacheId="vuex_store_"+y++,this._dispatching=!1,this._rootMutations=this._mutations=a,this._modules=c;var p=this.dispatch;if(this.dispatch=function(){for(var e=arguments.length,n=Array(e),o=0;o<e;o++)n[o]=arguments[o];p.apply(t,n)},!v)throw new Error("[vuex] must call Vue.use(Vuex) before creating a store instance.");var m=v.config.silent;v.config.silent=!0,this._vm=new v({data:{state:i}}),v.config.silent=m,this._setupModuleState(i,c),this._setupModuleMutations(c),this._setupMiddlewares(d,i),l&&this._setupMutationCheck()}return c(o,[{key:"dispatch",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];var i=!1;"object"===("undefined"==typeof t?"undefined":s(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(f(n)))}):r.apply(void 0,[a].concat(f(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"function"!=typeof t?void console.error("Vuex store.watch only accepts function."):this._vm.$watch(function(){return t(o.state)},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){v.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;r<n;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,"state",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=[p].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.state},set:function(t){throw new Error("[vuex] Vuex root state is read only.")}}]),o}();"undefined"!=typeof window&&window.Vue&&r(window.Vue);var _={Store:m,install:r,createLogger:a};return _});