diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b25f8b01..bf09b7f0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +# [3.3.0](https://github.com/vuejs/vuex/compare/v3.2.0...v3.3.0) (2020-04-25) + + +### Bug Fixes + +* Prepend devtool handler ([#1358](https://github.com/vuejs/vuex/issues/1358)) ([a39d076](https://github.com/vuejs/vuex/commit/a39d0767e4041cdd5cf8050774106c01d39024e0)), closes [vuejs/vue-devtools#678](https://github.com/vuejs/vue-devtools/issues/678) +* **types:** Add `devtools` to store options type ([#1478](https://github.com/vuejs/vuex/issues/1478)) ([38c11dc](https://github.com/vuejs/vuex/commit/38c11dcbaea7d7e661a1623cabb5aef7c6e47ba7)) + + +### Features + +* Add `prepend` option for `subscribe` and `subscribeAction` ([#1358](https://github.com/vuejs/vuex/issues/1358)) ([a39d076](https://github.com/vuejs/vuex/commit/a39d0767e4041cdd5cf8050774106c01d39024e0)) +* **logger:** `createLogger` can optionally log actions ([#987](https://github.com/vuejs/vuex/issues/987)) ([18be128](https://github.com/vuejs/vuex/commit/18be128ad933d1fca6da05c060f7664ce0c819ae)) + + + # [3.2.0](https://github.com/vuejs/vuex/compare/v3.1.3...v3.2.0) (2020-04-19) diff --git a/dist/logger.js b/dist/logger.js index 39a7c8888..cdcde6763 100644 --- a/dist/logger.js +++ b/dist/logger.js @@ -62,49 +62,81 @@ var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return true; }; var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; }; var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; }; + var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; + var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; + var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; + var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; var logger = ref.logger; if ( logger === void 0 ) logger = console; return function (store) { var prevState = deepCopy(store.state); - store.subscribe(function (mutation, state) { - if (typeof logger === 'undefined') { - return - } - var nextState = deepCopy(state); - - if (filter(mutation, prevState, nextState)) { - var time = new Date(); - var formattedTime = " @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3)); - var formattedMutation = mutationTransformer(mutation); - var message = "mutation " + (mutation.type) + formattedTime; - var startMessage = collapsed - ? logger.groupCollapsed - : logger.group; - - // render - try { - startMessage.call(logger, message); - } catch (e) { - console.log(message); + if (typeof logger === 'undefined') { + return + } + + if (logMutations) { + store.subscribe(function (mutation, state) { + var nextState = deepCopy(state); + + if (filter(mutation, prevState, nextState)) { + var formattedTime = getFormattedTime(); + var formattedMutation = mutationTransformer(mutation); + var message = "mutation " + (mutation.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); + logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); + logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + endMessage(logger); } - logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); - logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); - logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + prevState = nextState; + }); + } - try { - logger.groupEnd(); - } catch (e) { - logger.log('—— log end ——'); + if (logActions) { + store.subscribeAction(function (action, state) { + if (actionFilter(action, state)) { + var formattedTime = getFormattedTime(); + var formattedAction = actionTransformer(action); + var message = "action " + (action.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); + endMessage(logger); } - } + }); + } + } + } - prevState = nextState; - }); + function startMessage (logger, message, collapsed) { + var startMessage = collapsed + ? logger.groupCollapsed + : logger.group; + + // render + try { + startMessage.call(logger, message); + } catch (e) { + logger.log(message); + } + } + + function endMessage (logger) { + try { + logger.groupEnd(); + } catch (e) { + logger.log('—— log end ——'); } } + function getFormattedTime () { + var time = new Date(); + return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) + } + function repeat (str, times) { return (new Array(times + 1)).join(str) } diff --git a/dist/vuex.common.js b/dist/vuex.common.js index 1cba9da68..66df3178c 100644 --- a/dist/vuex.common.js +++ b/dist/vuex.common.js @@ -1,5 +1,5 @@ /** - * vuex v3.2.0 + * vuex v3.3.0 * (c) 2020 Evan You * @license MIT */ @@ -61,7 +61,11 @@ function devtoolPlugin (store) { store.subscribe(function (mutation, state) { devtoolHook.emit('vuex:mutation', mutation, state); - }); + }, { prepend: true }); + + store.subscribeAction(function (action, state) { + devtoolHook.emit('vuex:action', action, state); + }, { prepend: true }); } /** @@ -469,13 +473,13 @@ Store.prototype.dispatch = function dispatch (_type, _payload) { }) }; -Store.prototype.subscribe = function subscribe (fn) { - return genericSubscribe(fn, this._subscribers) +Store.prototype.subscribe = function subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) }; -Store.prototype.subscribeAction = function subscribeAction (fn) { +Store.prototype.subscribeAction = function subscribeAction (fn, options) { var subs = typeof fn === 'function' ? { before: fn } : fn; - return genericSubscribe(subs, this._actionSubscribers) + return genericSubscribe(subs, this._actionSubscribers, options) }; Store.prototype.watch = function watch (getter, cb, options) { @@ -552,9 +556,11 @@ Store.prototype._withCommit = function _withCommit (fn) { Object.defineProperties( Store.prototype, prototypeAccessors$1 ); -function genericSubscribe (fn, subs) { +function genericSubscribe (fn, subs, options) { if (subs.indexOf(fn) < 0) { - subs.push(fn); + options && options.prepend + ? subs.unshift(fn) + : subs.push(fn); } return function () { var i = subs.indexOf(fn); @@ -1062,7 +1068,7 @@ function getModuleByNamespace (store, helper, namespace) { var index = { Store: Store, install: install, - version: '3.2.0', + version: '3.3.0', mapState: mapState, mapMutations: mapMutations, mapGetters: mapGetters, diff --git a/dist/vuex.esm.browser.js b/dist/vuex.esm.browser.js index d6ab28815..17fece11f 100644 --- a/dist/vuex.esm.browser.js +++ b/dist/vuex.esm.browser.js @@ -1,5 +1,5 @@ /** - * vuex v3.2.0 + * vuex v3.3.0 * (c) 2020 Evan You * @license MIT */ @@ -57,7 +57,11 @@ function devtoolPlugin (store) { store.subscribe((mutation, state) => { devtoolHook.emit('vuex:mutation', mutation, state); - }); + }, { prepend: true }); + + store.subscribeAction((action, state) => { + devtoolHook.emit('vuex:action', action, state); + }, { prepend: true }); } /** @@ -455,13 +459,13 @@ class Store { }) } - subscribe (fn) { - return genericSubscribe(fn, this._subscribers) + subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) } - subscribeAction (fn) { + subscribeAction (fn, options) { const subs = typeof fn === 'function' ? { before: fn } : fn; - return genericSubscribe(subs, this._actionSubscribers) + return genericSubscribe(subs, this._actionSubscribers, options) } watch (getter, cb, options) { @@ -529,9 +533,11 @@ class Store { } } -function genericSubscribe (fn, subs) { +function genericSubscribe (fn, subs, options) { if (subs.indexOf(fn) < 0) { - subs.push(fn); + options && options.prepend + ? subs.unshift(fn) + : subs.push(fn); } return () => { const i = subs.indexOf(fn); @@ -1019,7 +1025,7 @@ function getModuleByNamespace (store, helper, namespace) { var index_esm = { Store, install, - version: '3.2.0', + version: '3.3.0', mapState, mapMutations, mapGetters, diff --git a/dist/vuex.esm.browser.min.js b/dist/vuex.esm.browser.min.js index eb14681b3..3952019a0 100644 --- a/dist/vuex.esm.browser.min.js +++ b/dist/vuex.esm.browser.min.js @@ -1,6 +1,6 @@ /** - * vuex v3.2.0 + * vuex v3.3.0 * (c) 2020 Evan You * @license MIT */ -const t=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function e(t,e){Object.keys(t).forEach(s=>e(t[s],s))}function s(t){return null!==t&&"object"==typeof t}class i{constructor(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;const s=t.state;this.state=("function"==typeof s?s():s)||{}}get namespaced(){return!!this._rawModule.namespaced}addChild(t,e){this._children[t]=e}removeChild(t){delete this._children[t]}getChild(t){return this._children[t]}hasChild(t){return t in this._children}update(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)}forEachChild(t){e(this._children,t)}forEachGetter(t){this._rawModule.getters&&e(this._rawModule.getters,t)}forEachAction(t){this._rawModule.actions&&e(this._rawModule.actions,t)}forEachMutation(t){this._rawModule.mutations&&e(this._rawModule.mutations,t)}}class o{constructor(t){this.register([],t,!1)}get(t){return t.reduce((t,e)=>t.getChild(e),this.root)}getNamespace(t){let e=this.root;return t.reduce((t,s)=>t+((e=e.getChild(s)).namespaced?s+"/":""),"")}update(t){!function t(e,s,i){s.update(i);if(i.modules)for(const o in i.modules){if(!s.getChild(o))return;t(e.concat(o),s.getChild(o),i.modules[o])}}([],this.root,t)}register(t,s,o=!0){const n=new i(s,o);if(0===t.length)this.root=n;else{this.get(t.slice(0,-1)).addChild(t[t.length-1],n)}s.modules&&e(s.modules,(e,s)=>{this.register(t.concat(s),e,o)})}unregister(t){const e=this.get(t.slice(0,-1)),s=t[t.length-1];e.getChild(s).runtime&&e.removeChild(s)}isRegistered(t){const e=this.get(t.slice(0,-1)),s=t[t.length-1];return e.hasChild(s)}}let n;class r{constructor(e={}){!n&&"undefined"!=typeof window&&window.Vue&&p(window.Vue);const{plugins:s=[],strict:i=!1}=e;this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new o(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new n,this._makeLocalGettersCache=Object.create(null);const r=this,{dispatch:c,commit:a}=this;this.dispatch=function(t,e){return c.call(r,t,e)},this.commit=function(t,e,s){return a.call(r,t,e,s)},this.strict=i;const l=this._modules.root.state;h(this,l,[],this._modules.root),u(this,l),s.forEach(t=>t(this)),(void 0!==e.devtools?e.devtools:n.config.devtools)&&function(e){t&&(e._devtoolHook=t,t.emit("vuex:init",e),t.on("vuex:travel-to-state",t=>{e.replaceState(t)}),e.subscribe((e,s)=>{t.emit("vuex:mutation",e,s)}))}(this)}get state(){return this._vm._data.$$state}set state(t){}commit(t,e,s){const{type:i,payload:o,options:n}=d(t,e,s),r={type:i,payload:o},c=this._mutations[i];c&&(this._withCommit(()=>{c.forEach(function(t){t(o)})}),this._subscribers.slice().forEach(t=>t(r,this.state)))}dispatch(t,e){const{type:s,payload:i}=d(t,e),o={type:s,payload:i},n=this._actions[s];if(n){try{this._actionSubscribers.slice().filter(t=>t.before).forEach(t=>t.before(o,this.state))}catch(t){}return(n.length>1?Promise.all(n.map(t=>t(i))):n[0](i)).then(t=>{try{this._actionSubscribers.filter(t=>t.after).forEach(t=>t.after(o,this.state))}catch(t){}return t})}}subscribe(t){return c(t,this._subscribers)}subscribeAction(t){return c("function"==typeof t?{before:t}:t,this._actionSubscribers)}watch(t,e,s){return this._watcherVM.$watch(()=>t(this.state,this.getters),e,s)}replaceState(t){this._withCommit(()=>{this._vm._data.$$state=t})}registerModule(t,e,s={}){"string"==typeof t&&(t=[t]),this._modules.register(t,e),h(this,this.state,t,this._modules.get(t),s.preserveState),u(this,this.state)}unregisterModule(t){"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit(()=>{const e=l(this.state,t.slice(0,-1));n.delete(e,t[t.length-1])}),a(this)}hasModule(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)}hotUpdate(t){this._modules.update(t),a(this,!0)}_withCommit(t){const e=this._committing;this._committing=!0,t(),this._committing=e}}function c(t,e){return e.indexOf(t)<0&&e.push(t),()=>{const s=e.indexOf(t);s>-1&&e.splice(s,1)}}function a(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);const s=t.state;h(t,s,[],t._modules.root,!0),u(t,s,e)}function u(t,s,i){const o=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);const r=t._wrappedGetters,c={};e(r,(e,s)=>{c[s]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,s,{get:()=>t._vm[s],enumerable:!0})});const a=n.config.silent;n.config.silent=!0,t._vm=new n({data:{$$state:s},computed:c}),n.config.silent=a,t.strict&&function(t){t._vm.$watch(function(){return this._data.$$state},()=>{},{deep:!0,sync:!0})}(t),o&&(i&&t._withCommit(()=>{o._data.$$state=null}),n.nextTick(()=>o.$destroy()))}function h(t,e,s,i,o){const r=!s.length,c=t._modules.getNamespace(s);if(i.namespaced&&(t._modulesNamespaceMap[c],t._modulesNamespaceMap[c]=i),!r&&!o){const o=l(e,s.slice(0,-1)),r=s[s.length-1];t._withCommit(()=>{n.set(o,r,i.state)})}const a=i.context=function(t,e,s){const i=""===e,o={dispatch:i?t.dispatch:(s,i,o)=>{const n=d(s,i,o),{payload:r,options:c}=n;let{type:a}=n;return c&&c.root||(a=e+a),t.dispatch(a,r)},commit:i?t.commit:(s,i,o)=>{const n=d(s,i,o),{payload:r,options:c}=n;let{type:a}=n;c&&c.root||(a=e+a),t.commit(a,r,c)}};return Object.defineProperties(o,{getters:{get:i?()=>t.getters:()=>(function(t,e){if(!t._makeLocalGettersCache[e]){const s={},i=e.length;Object.keys(t.getters).forEach(o=>{if(o.slice(0,i)!==e)return;const n=o.slice(i);Object.defineProperty(s,n,{get:()=>t.getters[o],enumerable:!0})}),t._makeLocalGettersCache[e]=s}return t._makeLocalGettersCache[e]})(t,e)},state:{get:()=>l(t.state,s)}}),o}(t,c,s);i.forEachMutation((e,s)=>{!function(t,e,s,i){(t._mutations[e]||(t._mutations[e]=[])).push(function(e){s.call(t,i.state,e)})}(t,c+s,e,a)}),i.forEachAction((e,s)=>{const i=e.root?s:c+s,o=e.handler||e;!function(t,e,s,i){(t._actions[e]||(t._actions[e]=[])).push(function(e){let o=s.call(t,{dispatch:i.dispatch,commit:i.commit,getters:i.getters,state:i.state,rootGetters:t.getters,rootState:t.state},e);var n;return(n=o)&&"function"==typeof n.then||(o=Promise.resolve(o)),t._devtoolHook?o.catch(e=>{throw t._devtoolHook.emit("vuex:error",e),e}):o})}(t,i,o,a)}),i.forEachGetter((e,s)=>{!function(t,e,s,i){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return s(i.state,i.getters,t.state,t.getters)}}(t,c+s,e,a)}),i.forEachChild((i,n)=>{h(t,e,s.concat(n),i,o)})}function l(t,e){return e.reduce((t,e)=>t[e],t)}function d(t,e,i){return s(t)&&t.type&&(i=e,e=t,t=t.type),{type:t,payload:e,options:i}}function p(t){n&&t===n||function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:e});else{const s=t.prototype._init;t.prototype._init=function(t={}){t.init=t.init?[e].concat(t.init):e,s.call(this,t)}}function e(){const t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(n=t)}const m=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{s[e]=function(){let e=this.$store.state,s=this.$store.getters;if(t){const i=v(this.$store,"mapState",t);if(!i)return;e=i.context.state,s=i.context.getters}return"function"==typeof i?i.call(this,e,s):e[i]},s[e].vuex=!0}),s}),f=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{s[e]=function(...e){let s=this.$store.commit;if(t){const e=v(this.$store,"mapMutations",t);if(!e)return;s=e.context.commit}return"function"==typeof i?i.apply(this,[s].concat(e)):s.apply(this.$store,[i].concat(e))}}),s}),_=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{i=t+i,s[e]=function(){if(!t||v(this.$store,"mapGetters",t))return this.$store.getters[i]},s[e].vuex=!0}),s}),g=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{s[e]=function(...e){let s=this.$store.dispatch;if(t){const e=v(this.$store,"mapActions",t);if(!e)return;s=e.context.dispatch}return"function"==typeof i?i.apply(this,[s].concat(e)):s.apply(this.$store,[i].concat(e))}}),s}),y=t=>({mapState:m.bind(null,t),mapGetters:_.bind(null,t),mapMutations:f.bind(null,t),mapActions:g.bind(null,t)});function b(t){return function(t){return Array.isArray(t)||s(t)}(t)?Array.isArray(t)?t.map(t=>({key:t,val:t})):Object.keys(t).map(e=>({key:e,val:t[e]})):[]}function w(t){return(e,s)=>("string"!=typeof e?(s=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,s))}function v(t,e,s){return t._modulesNamespaceMap[s]}export default{Store:r,install:p,version:"3.2.0",mapState:m,mapMutations:f,mapGetters:_,mapActions:g,createNamespacedHelpers:y};export{r as Store,p as install,m as mapState,f as mapMutations,_ as mapGetters,g as mapActions,y as createNamespacedHelpers}; \ No newline at end of file +const t=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function e(t,e){Object.keys(t).forEach(s=>e(t[s],s))}function s(t){return null!==t&&"object"==typeof t}class i{constructor(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;const s=t.state;this.state=("function"==typeof s?s():s)||{}}get namespaced(){return!!this._rawModule.namespaced}addChild(t,e){this._children[t]=e}removeChild(t){delete this._children[t]}getChild(t){return this._children[t]}hasChild(t){return t in this._children}update(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)}forEachChild(t){e(this._children,t)}forEachGetter(t){this._rawModule.getters&&e(this._rawModule.getters,t)}forEachAction(t){this._rawModule.actions&&e(this._rawModule.actions,t)}forEachMutation(t){this._rawModule.mutations&&e(this._rawModule.mutations,t)}}class o{constructor(t){this.register([],t,!1)}get(t){return t.reduce((t,e)=>t.getChild(e),this.root)}getNamespace(t){let e=this.root;return t.reduce((t,s)=>t+((e=e.getChild(s)).namespaced?s+"/":""),"")}update(t){!function t(e,s,i){s.update(i);if(i.modules)for(const o in i.modules){if(!s.getChild(o))return;t(e.concat(o),s.getChild(o),i.modules[o])}}([],this.root,t)}register(t,s,o=!0){const n=new i(s,o);if(0===t.length)this.root=n;else{this.get(t.slice(0,-1)).addChild(t[t.length-1],n)}s.modules&&e(s.modules,(e,s)=>{this.register(t.concat(s),e,o)})}unregister(t){const e=this.get(t.slice(0,-1)),s=t[t.length-1];e.getChild(s).runtime&&e.removeChild(s)}isRegistered(t){const e=this.get(t.slice(0,-1)),s=t[t.length-1];return e.hasChild(s)}}let n;class r{constructor(e={}){!n&&"undefined"!=typeof window&&window.Vue&&p(window.Vue);const{plugins:s=[],strict:i=!1}=e;this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new o(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new n,this._makeLocalGettersCache=Object.create(null);const r=this,{dispatch:c,commit:a}=this;this.dispatch=function(t,e){return c.call(r,t,e)},this.commit=function(t,e,s){return a.call(r,t,e,s)},this.strict=i;const l=this._modules.root.state;h(this,l,[],this._modules.root),u(this,l),s.forEach(t=>t(this)),(void 0!==e.devtools?e.devtools:n.config.devtools)&&function(e){t&&(e._devtoolHook=t,t.emit("vuex:init",e),t.on("vuex:travel-to-state",t=>{e.replaceState(t)}),e.subscribe((e,s)=>{t.emit("vuex:mutation",e,s)},{prepend:!0}),e.subscribeAction((e,s)=>{t.emit("vuex:action",e,s)},{prepend:!0}))}(this)}get state(){return this._vm._data.$$state}set state(t){}commit(t,e,s){const{type:i,payload:o,options:n}=d(t,e,s),r={type:i,payload:o},c=this._mutations[i];c&&(this._withCommit(()=>{c.forEach(function(t){t(o)})}),this._subscribers.slice().forEach(t=>t(r,this.state)))}dispatch(t,e){const{type:s,payload:i}=d(t,e),o={type:s,payload:i},n=this._actions[s];if(n){try{this._actionSubscribers.slice().filter(t=>t.before).forEach(t=>t.before(o,this.state))}catch(t){}return(n.length>1?Promise.all(n.map(t=>t(i))):n[0](i)).then(t=>{try{this._actionSubscribers.filter(t=>t.after).forEach(t=>t.after(o,this.state))}catch(t){}return t})}}subscribe(t,e){return c(t,this._subscribers,e)}subscribeAction(t,e){return c("function"==typeof t?{before:t}:t,this._actionSubscribers,e)}watch(t,e,s){return this._watcherVM.$watch(()=>t(this.state,this.getters),e,s)}replaceState(t){this._withCommit(()=>{this._vm._data.$$state=t})}registerModule(t,e,s={}){"string"==typeof t&&(t=[t]),this._modules.register(t,e),h(this,this.state,t,this._modules.get(t),s.preserveState),u(this,this.state)}unregisterModule(t){"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit(()=>{const e=l(this.state,t.slice(0,-1));n.delete(e,t[t.length-1])}),a(this)}hasModule(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)}hotUpdate(t){this._modules.update(t),a(this,!0)}_withCommit(t){const e=this._committing;this._committing=!0,t(),this._committing=e}}function c(t,e,s){return e.indexOf(t)<0&&(s&&s.prepend?e.unshift(t):e.push(t)),()=>{const s=e.indexOf(t);s>-1&&e.splice(s,1)}}function a(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);const s=t.state;h(t,s,[],t._modules.root,!0),u(t,s,e)}function u(t,s,i){const o=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);const r=t._wrappedGetters,c={};e(r,(e,s)=>{c[s]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,s,{get:()=>t._vm[s],enumerable:!0})});const a=n.config.silent;n.config.silent=!0,t._vm=new n({data:{$$state:s},computed:c}),n.config.silent=a,t.strict&&function(t){t._vm.$watch(function(){return this._data.$$state},()=>{},{deep:!0,sync:!0})}(t),o&&(i&&t._withCommit(()=>{o._data.$$state=null}),n.nextTick(()=>o.$destroy()))}function h(t,e,s,i,o){const r=!s.length,c=t._modules.getNamespace(s);if(i.namespaced&&(t._modulesNamespaceMap[c],t._modulesNamespaceMap[c]=i),!r&&!o){const o=l(e,s.slice(0,-1)),r=s[s.length-1];t._withCommit(()=>{n.set(o,r,i.state)})}const a=i.context=function(t,e,s){const i=""===e,o={dispatch:i?t.dispatch:(s,i,o)=>{const n=d(s,i,o),{payload:r,options:c}=n;let{type:a}=n;return c&&c.root||(a=e+a),t.dispatch(a,r)},commit:i?t.commit:(s,i,o)=>{const n=d(s,i,o),{payload:r,options:c}=n;let{type:a}=n;c&&c.root||(a=e+a),t.commit(a,r,c)}};return Object.defineProperties(o,{getters:{get:i?()=>t.getters:()=>(function(t,e){if(!t._makeLocalGettersCache[e]){const s={},i=e.length;Object.keys(t.getters).forEach(o=>{if(o.slice(0,i)!==e)return;const n=o.slice(i);Object.defineProperty(s,n,{get:()=>t.getters[o],enumerable:!0})}),t._makeLocalGettersCache[e]=s}return t._makeLocalGettersCache[e]})(t,e)},state:{get:()=>l(t.state,s)}}),o}(t,c,s);i.forEachMutation((e,s)=>{!function(t,e,s,i){(t._mutations[e]||(t._mutations[e]=[])).push(function(e){s.call(t,i.state,e)})}(t,c+s,e,a)}),i.forEachAction((e,s)=>{const i=e.root?s:c+s,o=e.handler||e;!function(t,e,s,i){(t._actions[e]||(t._actions[e]=[])).push(function(e){let o=s.call(t,{dispatch:i.dispatch,commit:i.commit,getters:i.getters,state:i.state,rootGetters:t.getters,rootState:t.state},e);var n;return(n=o)&&"function"==typeof n.then||(o=Promise.resolve(o)),t._devtoolHook?o.catch(e=>{throw t._devtoolHook.emit("vuex:error",e),e}):o})}(t,i,o,a)}),i.forEachGetter((e,s)=>{!function(t,e,s,i){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return s(i.state,i.getters,t.state,t.getters)}}(t,c+s,e,a)}),i.forEachChild((i,n)=>{h(t,e,s.concat(n),i,o)})}function l(t,e){return e.reduce((t,e)=>t[e],t)}function d(t,e,i){return s(t)&&t.type&&(i=e,e=t,t=t.type),{type:t,payload:e,options:i}}function p(t){n&&t===n||function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:e});else{const s=t.prototype._init;t.prototype._init=function(t={}){t.init=t.init?[e].concat(t.init):e,s.call(this,t)}}function e(){const t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(n=t)}const m=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{s[e]=function(){let e=this.$store.state,s=this.$store.getters;if(t){const i=v(this.$store,"mapState",t);if(!i)return;e=i.context.state,s=i.context.getters}return"function"==typeof i?i.call(this,e,s):e[i]},s[e].vuex=!0}),s}),f=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{s[e]=function(...e){let s=this.$store.commit;if(t){const e=v(this.$store,"mapMutations",t);if(!e)return;s=e.context.commit}return"function"==typeof i?i.apply(this,[s].concat(e)):s.apply(this.$store,[i].concat(e))}}),s}),_=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{i=t+i,s[e]=function(){if(!t||v(this.$store,"mapGetters",t))return this.$store.getters[i]},s[e].vuex=!0}),s}),g=w((t,e)=>{const s={};return b(e).forEach(({key:e,val:i})=>{s[e]=function(...e){let s=this.$store.dispatch;if(t){const e=v(this.$store,"mapActions",t);if(!e)return;s=e.context.dispatch}return"function"==typeof i?i.apply(this,[s].concat(e)):s.apply(this.$store,[i].concat(e))}}),s}),y=t=>({mapState:m.bind(null,t),mapGetters:_.bind(null,t),mapMutations:f.bind(null,t),mapActions:g.bind(null,t)});function b(t){return function(t){return Array.isArray(t)||s(t)}(t)?Array.isArray(t)?t.map(t=>({key:t,val:t})):Object.keys(t).map(e=>({key:e,val:t[e]})):[]}function w(t){return(e,s)=>("string"!=typeof e?(s=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,s))}function v(t,e,s){return t._modulesNamespaceMap[s]}export default{Store:r,install:p,version:"3.3.0",mapState:m,mapMutations:f,mapGetters:_,mapActions:g,createNamespacedHelpers:y};export{r as Store,p as install,m as mapState,f as mapMutations,_ as mapGetters,g as mapActions,y as createNamespacedHelpers}; \ No newline at end of file diff --git a/dist/vuex.esm.js b/dist/vuex.esm.js index 674bef4f5..8c0774bac 100644 --- a/dist/vuex.esm.js +++ b/dist/vuex.esm.js @@ -1,5 +1,5 @@ /** - * vuex v3.2.0 + * vuex v3.3.0 * (c) 2020 Evan You * @license MIT */ @@ -59,7 +59,11 @@ function devtoolPlugin (store) { store.subscribe(function (mutation, state) { devtoolHook.emit('vuex:mutation', mutation, state); - }); + }, { prepend: true }); + + store.subscribeAction(function (action, state) { + devtoolHook.emit('vuex:action', action, state); + }, { prepend: true }); } /** @@ -467,13 +471,13 @@ Store.prototype.dispatch = function dispatch (_type, _payload) { }) }; -Store.prototype.subscribe = function subscribe (fn) { - return genericSubscribe(fn, this._subscribers) +Store.prototype.subscribe = function subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) }; -Store.prototype.subscribeAction = function subscribeAction (fn) { +Store.prototype.subscribeAction = function subscribeAction (fn, options) { var subs = typeof fn === 'function' ? { before: fn } : fn; - return genericSubscribe(subs, this._actionSubscribers) + return genericSubscribe(subs, this._actionSubscribers, options) }; Store.prototype.watch = function watch (getter, cb, options) { @@ -550,9 +554,11 @@ Store.prototype._withCommit = function _withCommit (fn) { Object.defineProperties( Store.prototype, prototypeAccessors$1 ); -function genericSubscribe (fn, subs) { +function genericSubscribe (fn, subs, options) { if (subs.indexOf(fn) < 0) { - subs.push(fn); + options && options.prepend + ? subs.unshift(fn) + : subs.push(fn); } return function () { var i = subs.indexOf(fn); @@ -1060,7 +1066,7 @@ function getModuleByNamespace (store, helper, namespace) { var index_esm = { Store: Store, install: install, - version: '3.2.0', + version: '3.3.0', mapState: mapState, mapMutations: mapMutations, mapGetters: mapGetters, diff --git a/dist/vuex.js b/dist/vuex.js index b580e3d7a..2f893a40a 100644 --- a/dist/vuex.js +++ b/dist/vuex.js @@ -1,5 +1,5 @@ /** - * vuex v3.2.0 + * vuex v3.3.0 * (c) 2020 Evan You * @license MIT */ @@ -65,7 +65,11 @@ store.subscribe(function (mutation, state) { devtoolHook.emit('vuex:mutation', mutation, state); - }); + }, { prepend: true }); + + store.subscribeAction(function (action, state) { + devtoolHook.emit('vuex:action', action, state); + }, { prepend: true }); } /** @@ -472,13 +476,13 @@ }) }; - Store.prototype.subscribe = function subscribe (fn) { - return genericSubscribe(fn, this._subscribers) + Store.prototype.subscribe = function subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) }; - Store.prototype.subscribeAction = function subscribeAction (fn) { + Store.prototype.subscribeAction = function subscribeAction (fn, options) { var subs = typeof fn === 'function' ? { before: fn } : fn; - return genericSubscribe(subs, this._actionSubscribers) + return genericSubscribe(subs, this._actionSubscribers, options) }; Store.prototype.watch = function watch (getter, cb, options) { @@ -555,9 +559,11 @@ Object.defineProperties( Store.prototype, prototypeAccessors$1 ); - function genericSubscribe (fn, subs) { + function genericSubscribe (fn, subs, options) { if (subs.indexOf(fn) < 0) { - subs.push(fn); + options && options.prepend + ? subs.unshift(fn) + : subs.push(fn); } return function () { var i = subs.indexOf(fn); @@ -1065,7 +1071,7 @@ var index = { Store: Store, install: install, - version: '3.2.0', + version: '3.3.0', mapState: mapState, mapMutations: mapMutations, mapGetters: mapGetters, diff --git a/dist/vuex.min.js b/dist/vuex.min.js index 59664ba95..cd5ce4c56 100644 --- a/dist/vuex.min.js +++ b/dist/vuex.min.js @@ -1,6 +1,6 @@ /** - * vuex v3.2.0 + * vuex v3.3.0 * (c) 2020 Evan You * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Vuex=e()}(this,function(){"use strict";var t=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function e(t,e){Object.keys(t).forEach(function(n){return e(t[n],n)})}function n(t){return null!==t&&"object"==typeof t}var o=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)||{}},i={namespaced:{configurable:!0}};i.namespaced.get=function(){return!!this._rawModule.namespaced},o.prototype.addChild=function(t,e){this._children[t]=e},o.prototype.removeChild=function(t){delete this._children[t]},o.prototype.getChild=function(t){return this._children[t]},o.prototype.hasChild=function(t){return t in this._children},o.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)},o.prototype.forEachChild=function(t){e(this._children,t)},o.prototype.forEachGetter=function(t){this._rawModule.getters&&e(this._rawModule.getters,t)},o.prototype.forEachAction=function(t){this._rawModule.actions&&e(this._rawModule.actions,t)},o.prototype.forEachMutation=function(t){this._rawModule.mutations&&e(this._rawModule.mutations,t)},Object.defineProperties(o.prototype,i);var r,s=function(t){this.register([],t,!1)};s.prototype.get=function(t){return t.reduce(function(t,e){return t.getChild(e)},this.root)},s.prototype.getNamespace=function(t){var e=this.root;return t.reduce(function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")},"")},s.prototype.update=function(t){!function t(e,n,o){n.update(o);if(o.modules)for(var i in o.modules){if(!n.getChild(i))return;t(e.concat(i),n.getChild(i),o.modules[i])}}([],this.root,t)},s.prototype.register=function(t,n,i){var r=this;void 0===i&&(i=!0);var s=new o(n,i);0===t.length?this.root=s:this.get(t.slice(0,-1)).addChild(t[t.length-1],s);n.modules&&e(n.modules,function(e,n){r.register(t.concat(n),e,i)})},s.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];e.getChild(n).runtime&&e.removeChild(n)},s.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return e.hasChild(n)};var a=function(e){var n=this;void 0===e&&(e={}),!r&&"undefined"!=typeof window&&window.Vue&&m(window.Vue);var o=e.plugins;void 0===o&&(o=[]);var i=e.strict;void 0===i&&(i=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new s(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new r,this._makeLocalGettersCache=Object.create(null);var a=this,c=this.dispatch,u=this.commit;this.dispatch=function(t,e){return c.call(a,t,e)},this.commit=function(t,e,n){return u.call(a,t,e,n)},this.strict=i;var f=this._modules.root.state;p(this,f,[],this._modules.root),h(this,f),o.forEach(function(t){return t(n)}),(void 0!==e.devtools?e.devtools:r.config.devtools)&&function(e){t&&(e._devtoolHook=t,t.emit("vuex:init",e),t.on("vuex:travel-to-state",function(t){e.replaceState(t)}),e.subscribe(function(e,n){t.emit("vuex:mutation",e,n)}))}(this)},c={state:{configurable:!0}};function u(t,e){return e.indexOf(t)<0&&e.push(t),function(){var n=e.indexOf(t);n>-1&&e.splice(n,1)}}function f(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;p(t,n,[],t._modules.root,!0),h(t,n,e)}function h(t,n,o){var i=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);var s=t._wrappedGetters,a={};e(s,function(e,n){a[n]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,n,{get:function(){return t._vm[n]},enumerable:!0})});var c=r.config.silent;r.config.silent=!0,t._vm=new r({data:{$$state:n},computed:a}),r.config.silent=c,t.strict&&function(t){t._vm.$watch(function(){return this._data.$$state},function(){},{deep:!0,sync:!0})}(t),i&&(o&&t._withCommit(function(){i._data.$$state=null}),r.nextTick(function(){return i.$destroy()}))}function p(t,e,n,o,i){var s=!n.length,a=t._modules.getNamespace(n);if(o.namespaced&&(t._modulesNamespaceMap[a],t._modulesNamespaceMap[a]=o),!s&&!i){var c=l(e,n.slice(0,-1)),u=n[n.length-1];t._withCommit(function(){r.set(c,u,o.state)})}var f=o.context=function(t,e,n){var o=""===e,i={dispatch:o?t.dispatch:function(n,o,i){var r=d(n,o,i),s=r.payload,a=r.options,c=r.type;return a&&a.root||(c=e+c),t.dispatch(c,s)},commit:o?t.commit:function(n,o,i){var r=d(n,o,i),s=r.payload,a=r.options,c=r.type;a&&a.root||(c=e+c),t.commit(c,s,a)}};return Object.defineProperties(i,{getters:{get:o?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},o=e.length;Object.keys(t.getters).forEach(function(i){if(i.slice(0,o)===e){var r=i.slice(o);Object.defineProperty(n,r,{get:function(){return t.getters[i]},enumerable:!0})}}),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}(t,e)}},state:{get:function(){return l(t.state,n)}}}),i}(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,f)}),o.forEachAction(function(e,n){var o=e.root?n:a+n,i=e.handler||e;!function(t,e,n,o){(t._actions[e]||(t._actions[e]=[])).push(function(e){var i,r=n.call(t,{dispatch:o.dispatch,commit:o.commit,getters:o.getters,state:o.state,rootGetters:t.getters,rootState:t.state},e);return(i=r)&&"function"==typeof i.then||(r=Promise.resolve(r)),t._devtoolHook?r.catch(function(e){throw t._devtoolHook.emit("vuex:error",e),e}):r})}(t,o,i,f)}),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,f)}),o.forEachChild(function(o,r){p(t,e,n.concat(r),o,i)})}function l(t,e){return e.reduce(function(t,e){return t[e]},t)}function d(t,e,o){return n(t)&&t.type&&(o=e,e=t,t=t.type),{type:t,payload:e,options:o}}function m(t){r&&t===r||function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:n});else{var e=t.prototype._init;t.prototype._init=function(t){void 0===t&&(t={}),t.init=t.init?[n].concat(t.init):n,e.call(this,t)}}function n(){var t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(r=t)}c.state.get=function(){return this._vm._data.$$state},c.state.set=function(t){},a.prototype.commit=function(t,e,n){var o=this,i=d(t,e,n),r=i.type,s=i.payload,a={type:r,payload:s},c=this._mutations[r];c&&(this._withCommit(function(){c.forEach(function(t){t(s)})}),this._subscribers.slice().forEach(function(t){return t(a,o.state)}))},a.prototype.dispatch=function(t,e){var n=this,o=d(t,e),i=o.type,r=o.payload,s={type:i,payload:r},a=this._actions[i];if(a){try{this._actionSubscribers.slice().filter(function(t){return t.before}).forEach(function(t){return t.before(s,n.state)})}catch(t){}return(a.length>1?Promise.all(a.map(function(t){return t(r)})):a[0](r)).then(function(t){try{n._actionSubscribers.filter(function(t){return t.after}).forEach(function(t){return t.after(s,n.state)})}catch(t){}return t})}},a.prototype.subscribe=function(t){return u(t,this._subscribers)},a.prototype.subscribeAction=function(t){return u("function"==typeof t?{before:t}:t,this._actionSubscribers)},a.prototype.watch=function(t,e,n){var o=this;return this._watcherVM.$watch(function(){return t(o.state,o.getters)},e,n)},a.prototype.replaceState=function(t){var e=this;this._withCommit(function(){e._vm._data.$$state=t})},a.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),p(this,this.state,t,this._modules.get(t),n.preserveState),h(this,this.state)},a.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit(function(){var n=l(e.state,t.slice(0,-1));r.delete(n,t[t.length-1])}),f(this)},a.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},a.prototype.hotUpdate=function(t){this._modules.update(t),f(this,!0)},a.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(a.prototype,c);var v=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;n[o]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var o=$(this.$store,"mapState",t);if(!o)return;e=o.context.state,n=o.context.getters}return"function"==typeof i?i.call(this,e,n):e[i]},n[o].vuex=!0}),n}),_=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;n[o]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=this.$store.commit;if(t){var r=$(this.$store,"mapMutations",t);if(!r)return;o=r.context.commit}return"function"==typeof i?i.apply(this,[o].concat(e)):o.apply(this.$store,[i].concat(e))}}),n}),y=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;i=t+i,n[o]=function(){if(!t||$(this.$store,"mapGetters",t))return this.$store.getters[i]},n[o].vuex=!0}),n}),g=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;n[o]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=this.$store.dispatch;if(t){var r=$(this.$store,"mapActions",t);if(!r)return;o=r.context.dispatch}return"function"==typeof i?i.apply(this,[o].concat(e)):o.apply(this.$store,[i].concat(e))}}),n});function b(t){return function(t){return Array.isArray(t)||n(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 w(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function $(t,e,n){return t._modulesNamespaceMap[n]}return{Store:a,install:m,version:"3.2.0",mapState:v,mapMutations:_,mapGetters:y,mapActions:g,createNamespacedHelpers:function(t){return{mapState:v.bind(null,t),mapGetters:y.bind(null,t),mapMutations:_.bind(null,t),mapActions:g.bind(null,t)}}}}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Vuex=e()}(this,function(){"use strict";var t=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function e(t,e){Object.keys(t).forEach(function(n){return e(t[n],n)})}function n(t){return null!==t&&"object"==typeof t}var o=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)||{}},i={namespaced:{configurable:!0}};i.namespaced.get=function(){return!!this._rawModule.namespaced},o.prototype.addChild=function(t,e){this._children[t]=e},o.prototype.removeChild=function(t){delete this._children[t]},o.prototype.getChild=function(t){return this._children[t]},o.prototype.hasChild=function(t){return t in this._children},o.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)},o.prototype.forEachChild=function(t){e(this._children,t)},o.prototype.forEachGetter=function(t){this._rawModule.getters&&e(this._rawModule.getters,t)},o.prototype.forEachAction=function(t){this._rawModule.actions&&e(this._rawModule.actions,t)},o.prototype.forEachMutation=function(t){this._rawModule.mutations&&e(this._rawModule.mutations,t)},Object.defineProperties(o.prototype,i);var r,s=function(t){this.register([],t,!1)};s.prototype.get=function(t){return t.reduce(function(t,e){return t.getChild(e)},this.root)},s.prototype.getNamespace=function(t){var e=this.root;return t.reduce(function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")},"")},s.prototype.update=function(t){!function t(e,n,o){n.update(o);if(o.modules)for(var i in o.modules){if(!n.getChild(i))return;t(e.concat(i),n.getChild(i),o.modules[i])}}([],this.root,t)},s.prototype.register=function(t,n,i){var r=this;void 0===i&&(i=!0);var s=new o(n,i);0===t.length?this.root=s:this.get(t.slice(0,-1)).addChild(t[t.length-1],s);n.modules&&e(n.modules,function(e,n){r.register(t.concat(n),e,i)})},s.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];e.getChild(n).runtime&&e.removeChild(n)},s.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return e.hasChild(n)};var a=function(e){var n=this;void 0===e&&(e={}),!r&&"undefined"!=typeof window&&window.Vue&&m(window.Vue);var o=e.plugins;void 0===o&&(o=[]);var i=e.strict;void 0===i&&(i=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new s(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new r,this._makeLocalGettersCache=Object.create(null);var a=this,c=this.dispatch,u=this.commit;this.dispatch=function(t,e){return c.call(a,t,e)},this.commit=function(t,e,n){return u.call(a,t,e,n)},this.strict=i;var f=this._modules.root.state;p(this,f,[],this._modules.root),h(this,f),o.forEach(function(t){return t(n)}),(void 0!==e.devtools?e.devtools:r.config.devtools)&&function(e){t&&(e._devtoolHook=t,t.emit("vuex:init",e),t.on("vuex:travel-to-state",function(t){e.replaceState(t)}),e.subscribe(function(e,n){t.emit("vuex:mutation",e,n)},{prepend:!0}),e.subscribeAction(function(e,n){t.emit("vuex:action",e,n)},{prepend:!0}))}(this)},c={state:{configurable:!0}};function u(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 f(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;p(t,n,[],t._modules.root,!0),h(t,n,e)}function h(t,n,o){var i=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);var s=t._wrappedGetters,a={};e(s,function(e,n){a[n]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,n,{get:function(){return t._vm[n]},enumerable:!0})});var c=r.config.silent;r.config.silent=!0,t._vm=new r({data:{$$state:n},computed:a}),r.config.silent=c,t.strict&&function(t){t._vm.$watch(function(){return this._data.$$state},function(){},{deep:!0,sync:!0})}(t),i&&(o&&t._withCommit(function(){i._data.$$state=null}),r.nextTick(function(){return i.$destroy()}))}function p(t,e,n,o,i){var s=!n.length,a=t._modules.getNamespace(n);if(o.namespaced&&(t._modulesNamespaceMap[a],t._modulesNamespaceMap[a]=o),!s&&!i){var c=l(e,n.slice(0,-1)),u=n[n.length-1];t._withCommit(function(){r.set(c,u,o.state)})}var f=o.context=function(t,e,n){var o=""===e,i={dispatch:o?t.dispatch:function(n,o,i){var r=d(n,o,i),s=r.payload,a=r.options,c=r.type;return a&&a.root||(c=e+c),t.dispatch(c,s)},commit:o?t.commit:function(n,o,i){var r=d(n,o,i),s=r.payload,a=r.options,c=r.type;a&&a.root||(c=e+c),t.commit(c,s,a)}};return Object.defineProperties(i,{getters:{get:o?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},o=e.length;Object.keys(t.getters).forEach(function(i){if(i.slice(0,o)===e){var r=i.slice(o);Object.defineProperty(n,r,{get:function(){return t.getters[i]},enumerable:!0})}}),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}(t,e)}},state:{get:function(){return l(t.state,n)}}}),i}(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,f)}),o.forEachAction(function(e,n){var o=e.root?n:a+n,i=e.handler||e;!function(t,e,n,o){(t._actions[e]||(t._actions[e]=[])).push(function(e){var i,r=n.call(t,{dispatch:o.dispatch,commit:o.commit,getters:o.getters,state:o.state,rootGetters:t.getters,rootState:t.state},e);return(i=r)&&"function"==typeof i.then||(r=Promise.resolve(r)),t._devtoolHook?r.catch(function(e){throw t._devtoolHook.emit("vuex:error",e),e}):r})}(t,o,i,f)}),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,f)}),o.forEachChild(function(o,r){p(t,e,n.concat(r),o,i)})}function l(t,e){return e.reduce(function(t,e){return t[e]},t)}function d(t,e,o){return n(t)&&t.type&&(o=e,e=t,t=t.type),{type:t,payload:e,options:o}}function m(t){r&&t===r||function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:n});else{var e=t.prototype._init;t.prototype._init=function(t){void 0===t&&(t={}),t.init=t.init?[n].concat(t.init):n,e.call(this,t)}}function n(){var t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(r=t)}c.state.get=function(){return this._vm._data.$$state},c.state.set=function(t){},a.prototype.commit=function(t,e,n){var o=this,i=d(t,e,n),r=i.type,s=i.payload,a={type:r,payload:s},c=this._mutations[r];c&&(this._withCommit(function(){c.forEach(function(t){t(s)})}),this._subscribers.slice().forEach(function(t){return t(a,o.state)}))},a.prototype.dispatch=function(t,e){var n=this,o=d(t,e),i=o.type,r=o.payload,s={type:i,payload:r},a=this._actions[i];if(a){try{this._actionSubscribers.slice().filter(function(t){return t.before}).forEach(function(t){return t.before(s,n.state)})}catch(t){}return(a.length>1?Promise.all(a.map(function(t){return t(r)})):a[0](r)).then(function(t){try{n._actionSubscribers.filter(function(t){return t.after}).forEach(function(t){return t.after(s,n.state)})}catch(t){}return t})}},a.prototype.subscribe=function(t,e){return u(t,this._subscribers,e)},a.prototype.subscribeAction=function(t,e){return u("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},a.prototype.watch=function(t,e,n){var o=this;return this._watcherVM.$watch(function(){return t(o.state,o.getters)},e,n)},a.prototype.replaceState=function(t){var e=this;this._withCommit(function(){e._vm._data.$$state=t})},a.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),p(this,this.state,t,this._modules.get(t),n.preserveState),h(this,this.state)},a.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit(function(){var n=l(e.state,t.slice(0,-1));r.delete(n,t[t.length-1])}),f(this)},a.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},a.prototype.hotUpdate=function(t){this._modules.update(t),f(this,!0)},a.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(a.prototype,c);var v=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;n[o]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var o=$(this.$store,"mapState",t);if(!o)return;e=o.context.state,n=o.context.getters}return"function"==typeof i?i.call(this,e,n):e[i]},n[o].vuex=!0}),n}),_=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;n[o]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=this.$store.commit;if(t){var r=$(this.$store,"mapMutations",t);if(!r)return;o=r.context.commit}return"function"==typeof i?i.apply(this,[o].concat(e)):o.apply(this.$store,[i].concat(e))}}),n}),y=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;i=t+i,n[o]=function(){if(!t||$(this.$store,"mapGetters",t))return this.$store.getters[i]},n[o].vuex=!0}),n}),g=w(function(t,e){var n={};return b(e).forEach(function(e){var o=e.key,i=e.val;n[o]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=this.$store.dispatch;if(t){var r=$(this.$store,"mapActions",t);if(!r)return;o=r.context.dispatch}return"function"==typeof i?i.apply(this,[o].concat(e)):o.apply(this.$store,[i].concat(e))}}),n});function b(t){return function(t){return Array.isArray(t)||n(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 w(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function $(t,e,n){return t._modulesNamespaceMap[n]}return{Store:a,install:m,version:"3.3.0",mapState:v,mapMutations:_,mapGetters:y,mapActions:g,createNamespacedHelpers:function(t){return{mapState:v.bind(null,t),mapGetters:y.bind(null,t),mapMutations:_.bind(null,t),mapActions:g.bind(null,t)}}}}); \ No newline at end of file diff --git a/package.json b/package.json index 5e24a85a7..7b4ec8161 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex", - "version": "3.2.0", + "version": "3.3.0", "description": "state management for Vue.js", "main": "dist/vuex.common.js", "module": "dist/vuex.esm.js",