vuex.min.js 6.7 KB

123456
  1. /**
  2. * vuex v2.0.0-rc.5
  3. * (c) 2016 Evan You
  4. * @license MIT
  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){w&&(t._devtoolHook=w,w.emit("vuex:init",t),w.on("vuex:travel-to-state",function(e){t.replaceState(e)}),t.subscribe(function(t,e){w.emit("vuex:mutation",t,e)}))}function e(t){function e(){var t=this.$options;t.store?this.$store=t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}var n=Number(t.version.split(".")[0]);if(n>=2){var o=t.config._lifecycleHooks.indexOf("init")>-1;t.mixin(o?{init:e}:{beforeCreate:e})}else{var i=t.prototype._init;t.prototype._init=function(t){void 0===t&&(t={}),t.init=t.init?[e].concat(t.init):e,i.call(this,t)}}}function n(t){var e={};return s(t).forEach(function(t){var n=t.key,o=t.val;e[n]=function(){return"function"==typeof o?o.call(this,this.$store.state,this.$store.getters):this.$store.state[o]}}),e}function o(t){var e={};return s(t).forEach(function(t){var n=t.key,o=t.val;e[n]=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return this.$store.commit.apply(this.$store,[o].concat(t))}}),e}function i(t){var e={};return s(t).forEach(function(t){var n=t.key,o=t.val;e[n]=function(){return o in this.$store.getters||console.error("[vuex] unknown getter: "+o),this.$store.getters[o]}}),e}function r(t){var e={};return s(t).forEach(function(t){var n=t.key,o=t.val;e[n]=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return this.$store.dispatch.apply(this.$store,[o].concat(t))}}),e}function s(t){return Array.isArray(t)?t.map(function(t){return{key:t,val:t}}):Object.keys(t).map(function(e){return{key:e,val:t[e]}})}function c(t,e){if(!t)throw new Error("[vuex] "+e)}function u(t){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null);var e=t.state;f(t,e,[],t._options,!0),Object.keys(t._runtimeModules).forEach(function(n){f(t,e,n.split("."),t._runtimeModules[n],!0)}),a(t,e)}function a(t,e){var n=t._vm;t.getters={};var o=t._wrappedGetters,i={};Object.keys(o).forEach(function(e){var n=o[e];i[e]=function(){return n(t)},Object.defineProperty(t.getters,e,{get:function(){return t._vm[e]}})});var r=g.config.silent;g.config.silent=!0,t._vm=new g({data:{state:e},computed:i}),g.config.silent=r,t.strict&&m(t),n&&(t._withCommit(function(){n.state=null}),g.nextTick(function(){return n.$destroy()}))}function f(t,e,n,o,i){var r=!n.length,s=o.state,c=o.actions,u=o.mutations,a=o.getters,m=o.modules;if(!r&&!i){var v=y(e,n.slice(0,-1)),d=n[n.length-1];t._withCommit(function(){g.set(v,d,s||{})})}u&&Object.keys(u).forEach(function(e){h(t,e,u[e],n)}),c&&Object.keys(c).forEach(function(e){l(t,e,c[e],n)}),a&&p(t,a,n),m&&Object.keys(m).forEach(function(o){f(t,e,n.concat(o),m[o],i)})}function h(t,e,n,o){void 0===o&&(o=[]);var i=t._mutations[e]||(t._mutations[e]=[]);i.push(function(e){n(y(t.state,o),e)})}function l(t,e,n,o){void 0===o&&(o=[]);var i=t._actions[e]||(t._actions[e]=[]),r=t.dispatch,s=t.commit;i.push(function(e,i){var c=n({dispatch:r,commit:s,getters:t.getters,state:y(t.state,o),rootState:t.state},e,i);return d(c)||(c=Promise.resolve(c)),t._devtoolHook?c.catch(function(e){throw t._devtoolHook.emit("vuex:error",e),e}):c})}function p(t,e,n){Object.keys(e).forEach(function(o){var i=e[o];return t._wrappedGetters[o]?void console.error("[vuex] duplicate getter key: "+o):void(t._wrappedGetters[o]=function(t){return i(y(t.state,n),t.getters,t.state)})})}function m(t){t._vm.$watch("state",function(){c(t._committing,"Do not mutate vuex store state outside mutation handlers.")},{deep:!0,sync:!0})}function v(t){return null!==t&&"object"==typeof t}function d(t){return t&&"function"==typeof t.then}function y(t,e){return e.length?e.reduce(function(t,e){return t[e]},t):t}function _(t){return g?void console.error("[vuex] already installed. Vue.use(Vuex) should be called only once."):(g=t,void e(g))}var g,w="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,b=function(e){var n=this;void 0===e&&(e={}),c(g,"must call Vue.use(Vuex) before creating a store instance."),c("undefined"!=typeof Promise,"vuex requires a Promise polyfill in this browser.");var o=e.state;void 0===o&&(o={});var i=e.plugins;void 0===i&&(i=[]);var r=e.strict;void 0===r&&(r=!1),this._options=e,this._committing=!1,this._actions=Object.create(null),this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._runtimeModules=Object.create(null),this._subscribers=[],this._watcherVM=new g;var s=this,u=this,h=u.dispatch,l=u.commit;this.dispatch=function(t,e){return h.call(s,t,e)},this.commit=function(t,e,n){return l.call(s,t,e,n)},this.strict=r,f(this,o,[],e),a(this,o),i.concat(t).forEach(function(t){return t(n)})},O={state:{}};O.state.get=function(){return this._vm.state},O.state.set=function(t){c(!1,"Use store.replaceState() to explicit replace store state.")},b.prototype.commit=function(t,e,n){var o,i=this;v(t)&&t.type?(n=e,e=o=t,t=t.type):o={type:t,payload:e};var r=this._mutations[t];return r?(this._withCommit(function(){r.forEach(function(t){t(e)})}),void(n&&n.silent||this._subscribers.forEach(function(t){return t(o,i.state)}))):void console.error("[vuex] unknown mutation type: "+t)},b.prototype.dispatch=function(t,e){var n=this._actions[t];return n?n.length>1?Promise.all(n.map(function(t){return t(e)})):n[0](e):void console.error("[vuex] unknown action type: "+t)},b.prototype.subscribe=function(t){var e=this._subscribers;return e.indexOf(t)<0&&e.push(t),function(){var n=e.indexOf(t);n>-1&&e.splice(n,1)}},b.prototype.watch=function(t,e,n){var o=this;return c("function"==typeof t,"store.watch only accepts a function."),this._watcherVM.$watch(function(){return t(o.state)},e,n)},b.prototype.replaceState=function(t){var e=this;this._withCommit(function(){e._vm.state=t})},b.prototype.registerModule=function(t,e){"string"==typeof t&&(t=[t]),c(Array.isArray(t),"module path must be a string or an Array."),this._runtimeModules[t.join(".")]=e,f(this,this.state,t,e),a(this,this.state)},b.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),c(Array.isArray(t),"module path must be a string or an Array."),delete this._runtimeModules[t.join(".")],this._withCommit(function(){var n=y(e.state,t.slice(0,-1));g.delete(n,t[t.length-1])}),u(this)},b.prototype.hotUpdate=function(t){var e=this._options;if(t.actions&&(e.actions=t.actions),t.mutations&&(e.mutations=t.mutations),t.getters&&(e.getters=t.getters),t.modules)for(var n in t.modules)e.modules[n]=t.modules[n];u(this)},b.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(b.prototype,O),"undefined"!=typeof window&&window.Vue&&_(window.Vue);var x={Store:b,install:_,mapState:n,mapMutations:o,mapGetters:i,mapActions:r};return x});