forked from vuejs/vuex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuex.min.js
6 lines (6 loc) · 7.31 KB
/
vuex.min.js
1
2
3
4
5
6
/*!
* Vuex v2.0.0-rc.2
* (c) 2016 Evan You
* Released under the MIT License.
*/
!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){d&&(t._devtoolHook=d,d.emit("vuex:init",t),d.on("vuex:travel-to-state",function(e){t.replaceState(e)}),t.subscribe(function(t,e){d.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 i=t.config._lifecycleHooks.indexOf("init")>-1;t.mixin(i?{init:e}:{beforeCreate:e})}else!function(){var n=t.prototype._init;t.prototype._init=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];t.init=t.init?[e].concat(t.init):e,n.call(this,t)}}()}function n(t){var e={};return Object.keys(t).forEach(function(n){var i=t[n];e[n]=function(){return i.call(this,this.$store.state)}}),e}function i(t){var e={};return s(t).forEach(function(t){var n=t.key,i=t.val;e[n]=function(){for(var t,e=arguments.length,n=Array(e),o=0;o<e;o++)n[o]=arguments[o];return(t=this.$store).commit.apply(t,[i].concat(n))}}),e}function o(t){var e={};return s(t).forEach(function(t){var n=t.key,i=t.val;e[n]=function(){return i in this.$store.getters||console.error("[vuex] unknown getter: "+i),this.$store.getters[i]}}),e}function r(t){var e={};return s(t).forEach(function(t){var n=t.key,i=t.val;e[n]=function(){for(var t,e=arguments.length,n=Array(e),o=0;o<e;o++)n[o]=arguments[o];return(t=this.$store).dispatch.apply(t,[i].concat(n))}}),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 u(t,e){if(!t)throw new Error("[vuex] "+e)}function c(t,e,n){t.getters={};var i={};Object.keys(n).forEach(function(e){var o=n[e];i[e]=function(){return o(t._vm.state)},Object.defineProperty(t.getters,e,{get:function(){return t._vm[e]}})});var o=_.config.silent;_.config.silent=!0,t._vm=new _({data:{state:e},computed:i}),_.config.silent=o}function a(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return e?(Object.keys(e).forEach(function(i){var o=e[i],r=n.concat(i);o.getters&&Object.keys(o.getters).forEach(function(e){var n=o.getters[e];return t[e]?void console.error("[vuex] duplicate getter key: "+e):void(t[e]=function(t){return n(v(t,r),t)})}),a(t,o.modules,r)}),t):t}function f(t){t._vm.$watch("state",function(){u(t._committing,"Do not mutate vuex store state outside mutation handlers.")},{deep:!0,sync:!0})}function l(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":p(t))}function h(t){return t&&"function"==typeof t.then}function v(t,e){return e.reduce(function(t,e){return t[e]},t)}function m(t){return _?void console.error("[vuex] already installed. Vue.use(Vuex) should be called only once."):(_=t,void e(_))}var d="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,p="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},y=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},g=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),_=void 0,b=function(){function e(){var n=this,i=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];y(this,e),u(_,"must call Vue.use(Vuex) before creating a store instance."),u("undefined"!=typeof Promise,"vuex requires a Promise polyfill in this browser.");var o=i.state,r=void 0===o?{}:o,s=i.modules,l=void 0===s?{}:s,h=i.plugins,v=void 0===h?[]:h,m=i.strict,d=void 0!==m&&m;this._options=i,this._committing=!1,this._actions=Object.create(null),this._mutations=Object.create(null),this._subscribers=[],this._pendingActions=[];var p=this,g=this.dispatch,b=this.commit;this.dispatch=function(t,e){return g.call(p,t,e)},this.commit=function(t,e){return b.call(p,t,e)};var k=a(i.getters,l);c(this,r,k),this.module([],i),d&&f(this),v.concat(t).forEach(function(t){return t(n)})}return g(e,[{key:"replaceState",value:function(t){this._committing=!0,this._vm.state=t,this._committing=!1}},{key:"module",value:function(t,e,n){var i=this;this._committing=!0,"string"==typeof t&&(t=[t]),u(Array.isArray(t),"module path must be a string or an Array.");var o=!t.length,r=e.state,s=e.actions,c=e.mutations,a=e.modules;if(!o&&!n){var f=v(this.state,t.slice(0,-1)),l=t[t.length-1];_.set(f,l,r||{})}c&&Object.keys(c).forEach(function(e){i.mutation(e,c[e],t)}),s&&Object.keys(s).forEach(function(e){i.action(e,s[e],t)}),a&&Object.keys(a).forEach(function(e){i.module(t.concat(e),a[e],n)}),this._committing=!1}},{key:"mutation",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2],i=this._mutations[t]||(this._mutations[t]=[]),o=this;i.push(function(t){e(v(o.state,n),t)})}},{key:"action",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2],i=this._actions[t]||(this._actions[t]=[]),o=this,r=this.dispatch,s=this.commit;i.push(function(t,i){var u=e({dispatch:r,commit:s,state:v(o.state,n),rootState:o.state},t,i);return h(u)||(u=Promise.resolve(u)),o._devtoolHook?u["catch"](function(t){throw o._devtoolHook.emit("vuex:error",t),t}):u})}},{key:"commit",value:function(t,e){var n=this,i=void 0;l(t)&&t.type?(e=i=t,t=t.type):i={type:t,payload:e};var o=this._mutations[t];return o?(this._committing=!0,o.forEach(function(t){t(e)}),this._committing=!1,void(e&&e.silent||this._subscribers.forEach(function(t){return t(i,n.state)}))):void console.error("[vuex] unknown mutation type: "+t)}},{key:"dispatch",value:function(t,e){var n=this._actions[t];if(!n)return void console.error("[vuex] unknown action type: "+t);var i=n.length>1?Promise.all(n.map(function(t){return t(e)})):n[0](e),o=this._pendingActions;return o.push(i),i.then(function(t){return o.splice(o.indexOf(i),1),t})}},{key:"onActionsResolved",value:function(t){Promise.all(this._pendingActions).then(t)}},{key:"subscribe",value: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)}}},{key:"watch",value:function(t,e,n){var i=this;return u("function"==typeof t,"store.watch only accepts a function."),this._vm.$watch(function(){return t(i.state)},e,n)}},{key:"hotUpdate",value:function(t){var e=this;this._actions=Object.create(null),this._mutations=Object.create(null);var n=this._options;if(t.actions&&(n.actions=t.actions),t.mutations&&(n.mutations=t.mutations),t.modules)for(var i in t.modules)n.modules[i]=t.modules[i];this.module([],n,!0);var o=a(t.getters,t.modules);Object.keys(o).length&&!function(){var t=e._vm;c(e,e.state,o),e.strict&&f(e),e._committing=!0,t.state=null,e._committing=!1,_.nextTick(function(){return t.$destroy()})}()}},{key:"state",get:function(){return this._vm.state},set:function(t){u(!1,"Use store.replaceState() to explicit replace store state.")}}]),e}();"undefined"!=typeof window&&window.Vue&&m(window.Vue);var k={Store:b,install:m,mapState:n,mapMutations:i,mapGetters:o,mapActions:r};return k});