forked from vuejs/vuex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuex.min.js
6 lines (6 loc) · 10.2 KB
/
vuex.min.js
1
2
3
4
5
6
/**
* vuex v2.1.2
* (c) 2017 Evan You
* @license MIT
*/
!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){b&&(t._devtoolHook=b,b.emit("vuex:init",t),b.on("vuex:travel-to-state",function(e){t.replaceState(e)}),t.subscribe(function(t,e){b.emit("vuex:mutation",t,e)}))}function e(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 n(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function o(t,e,n){var o=t._modulesNamespaceMap[n];return o||console.error("[vuex] module namespace not found in "+e+"(): "+n),o}function r(t,e){Object.keys(t).forEach(function(n){return e(t[n],n)})}function i(t){return null!==t&&"object"==typeof t}function s(t){return t&&"function"==typeof t.then}function a(t,e){if(!t)throw new Error("[vuex] "+e)}function u(t,e){if(t.update(e),e.modules)for(var n in e.modules){if(!t.getChild(n))return void console.warn("[vuex] trying to add a new module '"+n+"' on hot reloading, manual reload is needed");u(t.getChild(n),e.modules[n])}}function c(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);var n=t.state;l(t,n,[],t._modules.root,!0),f(t,n,e)}function f(t,e,n){var o=t._vm;t.getters={};var i=t._wrappedGetters,s={};r(i,function(e,n){s[n]=function(){return e(t)},Object.defineProperty(t.getters,n,{get:function(){return t._vm[n]},enumerable:!0})});var a=A.config.silent;A.config.silent=!0,t._vm=new A({data:{state:e},computed:s}),A.config.silent=a,t.strict&&y(t),o&&(n&&t._withCommit(function(){o.state=null}),A.nextTick(function(){return o.$destroy()}))}function l(t,e,n,o,r){var i=!n.length,s=t._modules.getNamespace(n);if(s&&(t._modulesNamespaceMap[s]=o),!i&&!r){var a=g(e,n.slice(0,-1)),u=n[n.length-1];t._withCommit(function(){A.set(a,u,o.state)})}var c=o.context=p(t,s,n);o.forEachMutation(function(e,n){var o=s+n;d(t,o,e,c)}),o.forEachAction(function(e,n){var o=s+n;m(t,o,e,c)}),o.forEachGetter(function(e,n){var o=s+n;v(t,o,e,c)}),o.forEachChild(function(o,i){l(t,e,n.concat(i),o,r)})}function p(t,e,n){var o=""===e,r={dispatch:o?t.dispatch:function(n,o,r){var i=_(n,o,r),s=i.payload,a=i.options,u=i.type;return a&&a.root||(u=e+u,t._actions[u])?t.dispatch(u,s):void console.error("[vuex] unknown local action type: "+i.type+", global type: "+u)},commit:o?t.commit:function(n,o,r){var i=_(n,o,r),s=i.payload,a=i.options,u=i.type;return a&&a.root||(u=e+u,t._mutations[u])?void t.commit(u,s,a):void console.error("[vuex] unknown local mutation type: "+i.type+", global type: "+u)}};return Object.defineProperties(r,{getters:{get:o?function(){return t.getters}:function(){return h(t,e)}},state:{get:function(){return g(t.state,n)}}}),r}function h(t,e){var n={},o=e.length;return Object.keys(t.getters).forEach(function(r){if(r.slice(0,o)===e){var i=r.slice(o);Object.defineProperty(n,i,{get:function(){return t.getters[r]},enumerable:!0})}}),n}function d(t,e,n,o){var r=t._mutations[e]||(t._mutations[e]=[]);r.push(function(t){n(o.state,t)})}function m(t,e,n,o){var r=t._actions[e]||(t._actions[e]=[]);r.push(function(e,r){var i=n({dispatch:o.dispatch,commit:o.commit,getters:o.getters,state:o.state,rootGetters:t.getters,rootState:t.state},e,r);return s(i)||(i=Promise.resolve(i)),t._devtoolHook?i.catch(function(e){throw t._devtoolHook.emit("vuex:error",e),e}):i})}function v(t,e,n,o){return t._wrappedGetters[e]?void console.error("[vuex] duplicate getter key: "+e):void(t._wrappedGetters[e]=function(t){return n(o.state,o.getters,t.state,t.getters)})}function y(t){t._vm.$watch("state",function(){a(t._committing,"Do not mutate vuex store state outside mutation handlers.")},{deep:!0,sync:!0})}function g(t,e){return e.length?e.reduce(function(t,e){return t[e]},t):t}function _(t,e,n){return i(t)&&t.type&&(n=e,e=t,t=t.type),a("string"==typeof t,"Expects string as the type, but found "+typeof t+"."),{type:t,payload:e,options:n}}function w(t){return A?void console.error("[vuex] already installed. Vue.use(Vuex) should be called only once."):(A=t,void x(A))}var b="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,x=function(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 r=t.prototype._init;t.prototype._init=function(t){void 0===t&&(t={}),t.init=t.init?[e].concat(t.init):e,r.call(this,t)}}},M=n(function(t,n){var r={};return e(n).forEach(function(e){var n=e.key,i=e.val;r[n]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var r=o(this.$store,"mapState",t);if(!r)return;e=r.context.state,n=r.context.getters}return"function"==typeof i?i.call(this,e,n):e[i]}}),r}),O=n(function(t,n){var r={};return e(n).forEach(function(e){var n=e.key,i=e.val;i=t+i,r[n]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];if(!t||o(this.$store,"mapMutations",t))return this.$store.commit.apply(this.$store,[i].concat(e))}}),r}),E=n(function(t,n){var r={};return e(n).forEach(function(e){var n=e.key,i=e.val;i=t+i,r[n]=function(){if(!t||o(this.$store,"mapGetters",t))return i in this.$store.getters?this.$store.getters[i]:void console.error("[vuex] unknown getter: "+i)}}),r}),$=n(function(t,n){var r={};return e(n).forEach(function(e){var n=e.key,i=e.val;i=t+i,r[n]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];if(!t||o(this.$store,"mapActions",t))return this.$store.dispatch.apply(this.$store,[i].concat(e))}}),r}),k=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t},j={state:{},namespaced:{}};j.state.get=function(){return this._rawModule.state||{}},j.namespaced.get=function(){return!!this._rawModule.namespaced},k.prototype.addChild=function(t,e){this._children[t]=e},k.prototype.removeChild=function(t){delete this._children[t]},k.prototype.getChild=function(t){return this._children[t]},k.prototype.update=function(t){this._rawModule.namespaced=t.namespaced,t.actions&&(this._rawModule.actions=t.actions),t.mutations&&(this._rawModule.mutations=t.mutations),t.getters&&(this._rawModule.getters=t.getters)},k.prototype.forEachChild=function(t){r(this._children,t)},k.prototype.forEachGetter=function(t){this._rawModule.getters&&r(this._rawModule.getters,t)},k.prototype.forEachAction=function(t){this._rawModule.actions&&r(this._rawModule.actions,t)},k.prototype.forEachMutation=function(t){this._rawModule.mutations&&r(this._rawModule.mutations,t)},Object.defineProperties(k.prototype,j);var C=function(t){var e=this;this.root=new k(t,!1),t.modules&&r(t.modules,function(t,n){e.register([n],t,!1)})};C.prototype.get=function(t){return t.reduce(function(t,e){return t.getChild(e)},this.root)},C.prototype.getNamespace=function(t){var e=this.root;return t.reduce(function(t,n){return e=e.getChild(n),t+(e.namespaced?n+"/":"")},"")},C.prototype.update=function(t){u(this.root,t)},C.prototype.register=function(t,e,n){var o=this;void 0===n&&(n=!0);var i=this.get(t.slice(0,-1)),s=new k(e,n);i.addChild(t[t.length-1],s),e.modules&&r(e.modules,function(e,r){o.register(t.concat(r),e,n)})},C.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];e.getChild(n).runtime&&e.removeChild(n)};var A,G=function(e){var n=this;void 0===e&&(e={}),a(A,"must call Vue.use(Vuex) before creating a store instance."),a("undefined"!=typeof Promise,"vuex requires a Promise polyfill in this browser.");var o=e.state;void 0===o&&(o={});var r=e.plugins;void 0===r&&(r=[]);var i=e.strict;void 0===i&&(i=!1),this._committing=!1,this._actions=Object.create(null),this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new C(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new A;var s=this,u=this,c=u.dispatch,p=u.commit;this.dispatch=function(t,e){return c.call(s,t,e)},this.commit=function(t,e,n){return p.call(s,t,e,n)},this.strict=i,l(this,o,[],this._modules.root),f(this,o),r.concat(t).forEach(function(t){return t(n)})},V={state:{}};V.state.get=function(){return this._vm.$data.state},V.state.set=function(t){a(!1,"Use store.replaceState() to explicit replace store state.")},G.prototype.commit=function(t,e,n){var o=this,r=_(t,e,n),i=r.type,s=r.payload,a=r.options,u={type:i,payload:s},c=this._mutations[i];return c?(this._withCommit(function(){c.forEach(function(t){t(s)})}),this._subscribers.forEach(function(t){return t(u,o.state)}),void(a&&a.silent&&console.warn("[vuex] mutation type: "+i+". Silent option has been removed. Use the filter functionality in the vue-devtools"))):void console.error("[vuex] unknown mutation type: "+i)},G.prototype.dispatch=function(t,e){var n=_(t,e),o=n.type,r=n.payload,i=this._actions[o];return i?i.length>1?Promise.all(i.map(function(t){return t(r)})):i[0](r):void console.error("[vuex] unknown action type: "+o)},G.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)}},G.prototype.watch=function(t,e,n){var o=this;return a("function"==typeof t,"store.watch only accepts a function."),this._watcherVM.$watch(function(){return t(o.state,o.getters)},e,n)},G.prototype.replaceState=function(t){var e=this;this._withCommit(function(){e._vm.state=t})},G.prototype.registerModule=function(t,e){"string"==typeof t&&(t=[t]),a(Array.isArray(t),"module path must be a string or an Array."),this._modules.register(t,e),l(this,this.state,t,this._modules.get(t)),f(this,this.state)},G.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),a(Array.isArray(t),"module path must be a string or an Array."),this._modules.unregister(t),this._withCommit(function(){var n=g(e.state,t.slice(0,-1));A.delete(n,t[t.length-1])}),c(this)},G.prototype.hotUpdate=function(t){this._modules.update(t),c(this,!0)},G.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(G.prototype,V),"undefined"!=typeof window&&window.Vue&&w(window.Vue);var P={Store:G,install:w,version:"2.1.2",mapState:M,mapMutations:O,mapGetters:E,mapActions:$};return P});