1
0

vuex.min.js 5.5 KB

123456
  1. /*!
  2. * Vuex v0.5.1
  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(o){var n=t[o];n?Array.isArray(n)?n.push(e[o]):t[o]=[t[o],e[o]]:t[o]=e[o]}),t},{})}function e(t){if(Array.isArray(t))return t.map(e);if(t&&"object"===("undefined"==typeof t?"undefined":s["typeof"](t))){for(var o={},n=Object.keys(t),i=0,a=n.length;a>i;i++){var r=n[i];o[r]=e(t[r])}return o}return t}function o(t){var e=t.prototype._init;t.prototype._init=function(t){var o=this;t=t||{};var n=this.constructor.options,i=t.store||n.store;i?this.$store=i:t.parent&&t.parent.$store&&(this.$store=t.parent.$store);var s=t.vuex||n.vuex;s&&!function(){o.$store||console.warn("[vuex] store not injected. make sure to provide the store option in your root component.");var e=s.state,n=s.actions;e&&(t.computed=t.computed||{},Object.keys(e).forEach(function(o){t.computed[o]=function(){return e[o].call(this,this.$store.state)}})),n&&(t.methods=t.methods||{},Object.keys(n).forEach(function(e){t.methods[e]=function(){for(var t,o=arguments.length,i=Array(o),s=0;o>s;s++)i[s]=arguments[s];return(t=n[e]).call.apply(t,[this,this.$store].concat(i))}}))}(),e.call(this,t)}}function n(t){u=t,o(u)}function i(){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 o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,o,n){return o&&t(e.prototype,o),n&&t(e,n),e}}();var a="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,r={onInit:function(t,e){a&&(a.emit("vuex:init",e),a.on("vuex:travel-to-state",function(t){var o=e._vm._data;e._dispatching=!0,Object.keys(t).forEach(function(e){o[e]=t[e]}),e._dispatching=!1}))},onMutation:function(t,e){a&&a.emit("vuex:mutation",t,e)}},u=void 0,c=function(){function o(){var t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.state,i=void 0===n?{}:n,a=e.mutations,r=void 0===a?{}:a,c=e.modules,h=void 0===c?{}:c,f=e.middlewares,d=void 0===f?[]:f,p=e.strict,l=void 0===p?!1:p;s.classCallCheck(this,o),this._dispatching=!1,this._rootMutations=this._mutations=r,this._modules=h;var v=this.dispatch;this.dispatch=function(){for(var e=arguments.length,o=Array(e),n=0;e>n;n++)o[n]=arguments[n];v.apply(t,o)};var y=u.config.silent;u.config.silent=!0,this._vm=new u({data:i}),u.config.silent=y,this._setupModuleState(i,h),this._setupModuleMutations(h),this._setupMiddlewares(d,i),l&&this._setupMutationCheck()}return s.createClass(o,[{key:"dispatch",value:function(t){for(var o=this,n=arguments.length,i=Array(n>1?n-1:0),s=1;n>s;s++)i[s-1]=arguments[s];var a=this._mutations[t],r=this._prevSnapshot,u=this.state,c=void 0,h=void 0;a?(this._dispatching=!0,Array.isArray(a)?a.forEach(function(t){return t.apply(void 0,[u].concat(i))}):a.apply(void 0,[u].concat(i)),this._dispatching=!1,this._needSnapshots&&(c=this._prevSnapshot=e(u),h=e(i)),this._middlewares.forEach(function(e){e.onMutation&&(e.snapshot?e.onMutation({type:t,payload:h},c,r,o):e.onMutation({type:t,payload:i},u,o))})):console.warn("[vuex] Unknown mutation: "+t)}},{key:"watch",value:function(t,e,o){var n=this;return this._vm.$watch(function(){return"function"==typeof t?t(n.state):n._vm.$get(t)},e,o)}},{key:"hotUpdate",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.mutations,o=t.modules;this._rootMutations=this._mutations=e||this._rootMutations,this._setupModuleMutations(o||this._modules)}},{key:"_setupModuleState",value:function(t,e){var o=u.parsers.path.setPath;Object.keys(e).forEach(function(n){o(t,n,e[n].state||{})})}},{key:"_setupModuleMutations",value:function(e){this._modules=e;var o=u.parsers.path.getPath,n=[this._rootMutations];Object.keys(e).forEach(function(t){var i=e[t];if(i&&i.mutations){var s={};Object.keys(i.mutations).forEach(function(e){var n=i.mutations[e];s[e]=function(e){for(var i=arguments.length,s=Array(i>1?i-1:0),a=1;i>a;a++)s[a-1]=arguments[a];n.apply(void 0,[o(e,t)].concat(s))}}),n.push(s)}}),this._mutations=t(n)}},{key:"_setupMutationCheck",value:function(){var t=this,e=this._vm.$watch("__vuex__",function(t){return t}),o=this._vm._watchers[0].constructor;e(),new o(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,o){var n=this;this._middlewares=[r].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(o):null;this._middlewares.forEach(function(t){t.onInit&&t.onInit(t.snapshot?i:o,n)})}},{key:"state",get:function(){return this._vm._data},set:function(t){throw new Error("[vuex] Vuex root state is read only.")}}]),o}(),h={Store:c,install:n,createLogger:i};return h});