UNPKG

15.1 kBJavaScriptView Raw
1/*!
2 * vuex v4.0.2
3 * (c) 2021 Evan You
4 * @license MIT
5 */
6var Vuex=function(t){"use strict";var e="store";function n(){return"undefined"!=typeof navigator?window:"undefined"!=typeof global?global:{}}function o(t,e){var o=n().__VUE_DEVTOOLS_GLOBAL_HOOK__;if(o)o.emit("devtools-plugin:setup",t,e);else{var r=n();(r.__VUE_DEVTOOLS_PLUGINS__=r.__VUE_DEVTOOLS_PLUGINS__||[]).push({pluginDescriptor:t,setupFn:e})}}function r(t,e){if(void 0===e&&(e=[]),null===t||"object"!=typeof t)return t;var n,o=(n=function(e){return e.original===t},e.filter(n)[0]);if(o)return o.copy;var i=Array.isArray(t)?[]:{};return e.push({original:t,copy:i}),Object.keys(t).forEach((function(n){i[n]=r(t[n],e)})),i}function i(t,e){Object.keys(t).forEach((function(n){return e(t[n],n)}))}function a(t){return null!==t&&"object"==typeof t}function c(t,e,n){return e.indexOf(t)<0&&(n&&n.prepend?e.unshift(t):e.push(t)),function(){var n=e.indexOf(t);n>-1&&e.splice(n,1)}}function s(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),u(t,n,e)}function u(e,n,o){var r=e._state;e.getters={},e._makeLocalGettersCache=Object.create(null);var a=e._wrappedGetters,c={};i(a,(function(t,n){c[n]=function(t,e){return function(){return t(e)}}(t,e),Object.defineProperty(e.getters,n,{get:function(){return c[n]()},enumerable:!0})})),e._state=t.reactive({data:n}),e.strict&&function(e){t.watch((function(){return e._state.data}),(function(){}),{deep:!0,flush:"sync"})}(e),r&&o&&e._withCommit((function(){r.data=null}))}function l(t,e,n,o,r){var i=!n.length,a=t._modules.getNamespace(n);if(o.namespaced&&(t._modulesNamespaceMap[a],t._modulesNamespaceMap[a]=o),!i&&!r){var c=p(e,n.slice(0,-1)),s=n[n.length-1];t._withCommit((function(){c[s]=o.state}))}var u=o.context=function(t,e,n){var o=""===e,r={dispatch:o?t.dispatch:function(n,o,r){var i=d(n,o,r),a=i.payload,c=i.options,s=i.type;return c&&c.root||(s=e+s),t.dispatch(s,a)},commit:o?t.commit:function(n,o,r){var i=d(n,o,r),a=i.payload,c=i.options,s=i.type;c&&c.root||(s=e+s),t.commit(s,a,c)}};return Object.defineProperties(r,{getters:{get:o?function(){return t.getters}:function(){return f(t,e)}},state:{get:function(){return p(t.state,n)}}}),r}(t,a,n);o.forEachMutation((function(e,n){!function(t,e,n,o){(t._mutations[e]||(t._mutations[e]=[])).push((function(e){n.call(t,o.state,e)}))}(t,a+n,e,u)})),o.forEachAction((function(e,n){var o=e.root?n:a+n,r=e.handler||e;!function(t,e,n,o){(t._actions[e]||(t._actions[e]=[])).push((function(e){var r,i=n.call(t,{dispatch:o.dispatch,commit:o.commit,getters:o.getters,state:o.state,rootGetters:t.getters,rootState:t.state},e);return(r=i)&&"function"==typeof r.then||(i=Promise.resolve(i)),t._devtoolHook?i.catch((function(e){throw t._devtoolHook.emit("vuex:error",e),e})):i}))}(t,o,r,u)})),o.forEachGetter((function(e,n){!function(t,e,n,o){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return n(o.state,o.getters,t.state,t.getters)}}(t,a+n,e,u)})),o.forEachChild((function(o,i){l(t,e,n.concat(i),o,r)}))}function f(t,e){if(!t._makeLocalGettersCache[e]){var n={},o=e.length;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})}})),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}function p(t,e){return e.reduce((function(t,e){return t[e]}),t)}function d(t,e,n){return a(t)&&t.type&&(n=e,e=t,t=t.type),{type:t,payload:e,options:n}}var h="vuex:mutations",v="vuex:actions",m="vuex",g=0;function y(t,e){o({id:"org.vuejs.vuex",app:t,label:"Vuex",homepage:"https://next.vuex.vuejs.org/",logo:"https://vuejs.org/images/icons/favicon-96x96.png",packageName:"vuex",componentStateTypes:["vuex bindings"]},(function(n){n.addTimelineLayer({id:h,label:"Vuex Mutations",color:_}),n.addTimelineLayer({id:v,label:"Vuex Actions",color:_}),n.addInspector({id:m,label:"Vuex",icon:"storage",treeFilterPlaceholder:"Filter stores..."}),n.on.getInspectorTree((function(n){if(n.app===t&&n.inspectorId===m)if(n.filter){var o=[];O(o,e._modules.root,n.filter,""),n.rootNodes=o}else n.rootNodes=[E(e._modules.root,"")]})),n.on.getInspectorState((function(n){if(n.app===t&&n.inspectorId===m){var o=n.nodeId;f(e,o),n.state=function(t,e,n){e="root"===n?e:e[n];var o=Object.keys(e),r={state:Object.keys(t.state).map((function(e){return{key:e,editable:!0,value:t.state[e]}}))};if(o.length){var i=function(t){var e={};return Object.keys(t).forEach((function(n){var o=n.split("/");if(o.length>1){var r=e,i=o.pop();o.forEach((function(t){r[t]||(r[t]={_custom:{value:{},display:t,tooltip:"Module",abstract:!0}}),r=r[t]._custom.value})),r[i]=j((function(){return t[n]}))}else e[n]=j((function(){return t[n]}))})),e}(e);r.getters=Object.keys(i).map((function(t){return{key:t.endsWith("/")?w(t):t,editable:!1,value:j((function(){return i[t]}))}}))}return r}((r=e._modules,(a=(i=o).split("/").filter((function(t){return t}))).reduce((function(t,e,n){var o=t[e];if(!o)throw new Error('Missing module "'+e+'" for path "'+i+'".');return n===a.length-1?o:o._children}),"root"===i?r:r.root._children)),"root"===o?e.getters:e._makeLocalGettersCache,o)}var r,i,a})),n.on.editInspectorState((function(n){if(n.app===t&&n.inspectorId===m){var o=n.nodeId,r=n.path;"root"!==o&&(r=o.split("/").filter(Boolean).concat(r)),e._withCommit((function(){n.set(e._state.data,r,n.state.value)}))}})),e.subscribe((function(t,e){var o={};t.payload&&(o.payload=t.payload),o.state=e,n.notifyComponentUpdate(),n.sendInspectorTree(m),n.sendInspectorState(m),n.addTimelineEvent({layerId:h,event:{time:Date.now(),title:t.type,data:o}})})),e.subscribeAction({before:function(t,e){var o={};t.payload&&(o.payload=t.payload),t._id=g++,t._time=Date.now(),o.state=e,n.addTimelineEvent({layerId:v,event:{time:t._time,title:t.type,groupId:t._id,subtitle:"start",data:o}})},after:function(t,e){var o={},r=Date.now()-t._time;o.duration={_custom:{type:"duration",display:r+"ms",tooltip:"Action duration",value:r}},t.payload&&(o.payload=t.payload),o.state=e,n.addTimelineEvent({layerId:v,event:{time:Date.now(),title:t.type,groupId:t._id,subtitle:"end",data:o}})}})}))}var _=8702998,b={label:"namespaced",textColor:16777215,backgroundColor:6710886};function w(t){return t&&"root"!==t?t.split("/").slice(-2,-1)[0]:"Root"}function E(t,e){return{id:e||"root",label:w(e),tags:t.namespaced?[b]:[],children:Object.keys(t._children).map((function(n){return E(t._children[n],e+n+"/")}))}}function O(t,e,n,o){o.includes(n)&&t.push({id:o||"root",label:o.endsWith("/")?o.slice(0,o.length-1):o||"Root",tags:e.namespaced?[b]:[]}),Object.keys(e._children).forEach((function(r){O(t,e._children[r],n,o+r+"/")}))}function j(t){try{return t()}catch(t){return t}}var C=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;var n=t.state;this.state=("function"==typeof n?n():n)||{}},M={namespaced:{configurable:!0}};M.namespaced.get=function(){return!!this._rawModule.namespaced},C.prototype.addChild=function(t,e){this._children[t]=e},C.prototype.removeChild=function(t){delete this._children[t]},C.prototype.getChild=function(t){return this._children[t]},C.prototype.hasChild=function(t){return t in this._children},C.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)},C.prototype.forEachChild=function(t){i(this._children,t)},C.prototype.forEachGetter=function(t){this._rawModule.getters&&i(this._rawModule.getters,t)},C.prototype.forEachAction=function(t){this._rawModule.actions&&i(this._rawModule.actions,t)},C.prototype.forEachMutation=function(t){this._rawModule.mutations&&i(this._rawModule.mutations,t)},Object.defineProperties(C.prototype,M);var k=function(t){this.register([],t,!1)};function x(t,e,n){if(e.update(n),n.modules)for(var o in n.modules){if(!e.getChild(o))return;x(t.concat(o),e.getChild(o),n.modules[o])}}k.prototype.get=function(t){return t.reduce((function(t,e){return t.getChild(e)}),this.root)},k.prototype.getNamespace=function(t){var e=this.root;return t.reduce((function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")}),"")},k.prototype.update=function(t){x([],this.root,t)},k.prototype.register=function(t,e,n){var o=this;void 0===n&&(n=!0);var r=new C(e,n);0===t.length?this.root=r:this.get(t.slice(0,-1)).addChild(t[t.length-1],r);e.modules&&i(e.modules,(function(e,r){o.register(t.concat(r),e,n)}))},k.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1],o=e.getChild(n);o&&o.runtime&&e.removeChild(n)},k.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return!!e&&e.hasChild(n)};var S=function(t){var e=this;void 0===t&&(t={});var n=t.plugins;void 0===n&&(n=[]);var o=t.strict;void 0===o&&(o=!1);var r=t.devtools;this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new k(t),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._makeLocalGettersCache=Object.create(null),this._devtools=r;var i=this,a=this.dispatch,c=this.commit;this.dispatch=function(t,e){return a.call(i,t,e)},this.commit=function(t,e,n){return c.call(i,t,e,n)},this.strict=o;var s=this._modules.root.state;l(this,s,[],this._modules.root),u(this,s),n.forEach((function(t){return t(e)}))},A={state:{configurable:!0}};S.prototype.install=function(t,n){t.provide(n||e,this),t.config.globalProperties.$store=this,void 0!==this._devtools&&this._devtools&&y(t,this)},A.state.get=function(){return this._state.data},A.state.set=function(t){},S.prototype.commit=function(t,e,n){var o=this,r=d(t,e,n),i=r.type,a=r.payload,c={type:i,payload:a},s=this._mutations[i];s&&(this._withCommit((function(){s.forEach((function(t){t(a)}))})),this._subscribers.slice().forEach((function(t){return t(c,o.state)})))},S.prototype.dispatch=function(t,e){var n=this,o=d(t,e),r=o.type,i=o.payload,a={type:r,payload:i},c=this._actions[r];if(c){try{this._actionSubscribers.slice().filter((function(t){return t.before})).forEach((function(t){return t.before(a,n.state)}))}catch(t){}var s=c.length>1?Promise.all(c.map((function(t){return t(i)}))):c[0](i);return new Promise((function(t,e){s.then((function(e){try{n._actionSubscribers.filter((function(t){return t.after})).forEach((function(t){return t.after(a,n.state)}))}catch(t){}t(e)}),(function(t){try{n._actionSubscribers.filter((function(t){return t.error})).forEach((function(e){return e.error(a,n.state,t)}))}catch(t){}e(t)}))}))}},S.prototype.subscribe=function(t,e){return c(t,this._subscribers,e)},S.prototype.subscribeAction=function(t,e){return c("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},S.prototype.watch=function(e,n,o){var r=this;return t.watch((function(){return e(r.state,r.getters)}),n,Object.assign({},o))},S.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._state.data=t}))},S.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),l(this,this.state,t,this._modules.get(t),n.preserveState),u(this,this.state)},S.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit((function(){delete p(e.state,t.slice(0,-1))[t[t.length-1]]})),s(this)},S.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},S.prototype.hotUpdate=function(t){this._modules.update(t),s(this,!0)},S.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(S.prototype,A);var G=P((function(t,e){var n={};return T(e).forEach((function(e){var o=e.key,r=e.val;n[o]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var o=V(this.$store,"mapState",t);if(!o)return;e=o.context.state,n=o.context.getters}return"function"==typeof r?r.call(this,e,n):e[r]},n[o].vuex=!0})),n})),I=P((function(t,e){var n={};return T(e).forEach((function(e){var o=e.key,r=e.val;n[o]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=this.$store.commit;if(t){var i=V(this.$store,"mapMutations",t);if(!i)return;o=i.context.commit}return"function"==typeof r?r.apply(this,[o].concat(e)):o.apply(this.$store,[r].concat(e))}})),n})),L=P((function(t,e){var n={};return T(e).forEach((function(e){var o=e.key,r=e.val;r=t+r,n[o]=function(){if(!t||V(this.$store,"mapGetters",t))return this.$store.getters[r]},n[o].vuex=!0})),n})),N=P((function(t,e){var n={};return T(e).forEach((function(e){var o=e.key,r=e.val;n[o]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=this.$store.dispatch;if(t){var i=V(this.$store,"mapActions",t);if(!i)return;o=i.context.dispatch}return"function"==typeof r?r.apply(this,[o].concat(e)):o.apply(this.$store,[r].concat(e))}})),n}));function T(t){return function(t){return Array.isArray(t)||a(t)}(t)?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 P(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function V(t,e,n){return t._modulesNamespaceMap[n]}function $(t,e,n){var o=n?t.groupCollapsed:t.group;try{o.call(t,e)}catch(n){t.log(e)}}function D(t){try{t.groupEnd()}catch(e){t.log("—— log end ——")}}function F(){var t=new Date;return" @ "+U(t.getHours(),2)+":"+U(t.getMinutes(),2)+":"+U(t.getSeconds(),2)+"."+U(t.getMilliseconds(),3)}function U(t,e){return n="0",o=e-t.toString().length,new Array(o+1).join(n)+t;var n,o}return{version:"4.0.2",Store:S,storeKey:e,createStore:function(t){return new S(t)},useStore:function(n){return void 0===n&&(n=null),t.inject(null!==n?n:e)},mapState:G,mapMutations:I,mapGetters:L,mapActions:N,createNamespacedHelpers:function(t){return{mapState:G.bind(null,t),mapGetters:L.bind(null,t),mapMutations:I.bind(null,t),mapActions:N.bind(null,t)}},createLogger:function(t){void 0===t&&(t={});var e=t.collapsed;void 0===e&&(e=!0);var n=t.filter;void 0===n&&(n=function(t,e,n){return!0});var o=t.transformer;void 0===o&&(o=function(t){return t});var i=t.mutationTransformer;void 0===i&&(i=function(t){return t});var a=t.actionFilter;void 0===a&&(a=function(t,e){return!0});var c=t.actionTransformer;void 0===c&&(c=function(t){return t});var s=t.logMutations;void 0===s&&(s=!0);var u=t.logActions;void 0===u&&(u=!0);var l=t.logger;return void 0===l&&(l=console),function(t){var f=r(t.state);void 0!==l&&(s&&t.subscribe((function(t,a){var c=r(a);if(n(t,f,c)){var s=F(),u=i(t),p="mutation "+t.type+s;$(l,p,e),l.log("%c prev state","color: #9E9E9E; font-weight: bold",o(f)),l.log("%c mutation","color: #03A9F4; font-weight: bold",u),l.log("%c next state","color: #4CAF50; font-weight: bold",o(c)),D(l)}f=c})),u&&t.subscribeAction((function(t,n){if(a(t,n)){var o=F(),r=c(t),i="action "+t.type+o;$(l,i,e),l.log("%c action","color: #03A9F4; font-weight: bold",r),D(l)}})))}}}}(Vue);