vuex.min.js 5.3 KB

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