Comparing version 4.0.0 to 4.0.1
@@ -0,1 +1,7 @@ | ||
## [4.0.1](https://github.com/vuejs/vuex/compare/v4.0.0...v4.0.1) (2021-05-24) | ||
### Features | ||
* dx: add devtools integration ([#1949](https://github.com/vuejs/vuex/pull/1949)) | ||
# [4.0.0](https://github.com/vuejs/vuex/compare/v4.0.0-rc.2...v4.0.0) (2021-02-02) | ||
@@ -2,0 +8,0 @@ |
/*! | ||
* vuex v4.0.0 | ||
* vuex v4.0.1 | ||
* (c) 2021 Evan You | ||
@@ -9,2 +9,3 @@ * @license MIT | ||
var vue = require('vue'); | ||
var devtoolsApi = require('@vue/devtools-api'); | ||
@@ -19,29 +20,2 @@ var storeKey = 'store'; | ||
var target = typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
var devtoolHook = target.__VUE_DEVTOOLS_GLOBAL_HOOK__; | ||
function devtoolPlugin (store) { | ||
if (!devtoolHook) { return } | ||
store._devtoolHook = devtoolHook; | ||
devtoolHook.emit('vuex:init', store); | ||
devtoolHook.on('vuex:travel-to-state', function (targetState) { | ||
store.replaceState(targetState); | ||
}); | ||
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 }); | ||
} | ||
/** | ||
@@ -122,2 +96,530 @@ * Get the first item that pass the test | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = vue.reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && (process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
vue.watch(function () { return store._state.data; }, function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
var LABEL_VUEX_BINDINGS = 'vuex bindings'; | ||
var MUTATIONS_LAYER_ID = 'vuex:mutations'; | ||
var ACTIONS_LAYER_ID = 'vuex:actions'; | ||
var INSPECTOR_ID = 'vuex'; | ||
var actionId = 0; | ||
function addDevtools (app, store) { | ||
devtoolsApi.setupDevtoolsPlugin( | ||
{ | ||
id: 'org.vuejs.vuex', | ||
app: app, | ||
label: 'Vuex', | ||
homepage: 'https://next.vuex.vuejs.org/', | ||
logo: 'https://vuejs.org/images/icons/favicon-96x96.png', | ||
packageName: 'vuex', | ||
componentStateTypes: [LABEL_VUEX_BINDINGS] | ||
}, | ||
function (api) { | ||
api.addTimelineLayer({ | ||
id: MUTATIONS_LAYER_ID, | ||
label: 'Vuex Mutations', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addTimelineLayer({ | ||
id: ACTIONS_LAYER_ID, | ||
label: 'Vuex Actions', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addInspector({ | ||
id: INSPECTOR_ID, | ||
label: 'Vuex', | ||
icon: 'storage', | ||
treeFilterPlaceholder: 'Filter stores...' | ||
}); | ||
api.on.getInspectorTree(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
if (payload.filter) { | ||
var nodes = []; | ||
flattenStoreForInspectorTree(nodes, store._modules.root, payload.filter, ''); | ||
payload.rootNodes = nodes; | ||
} else { | ||
payload.rootNodes = [ | ||
formatStoreForInspectorTree(store._modules.root, '') | ||
]; | ||
} | ||
} | ||
}); | ||
api.on.getInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
makeLocalGetters(store, modulePath); | ||
payload.state = formatStoreForInspectorState( | ||
getStoreModule(store._modules, modulePath), | ||
store._makeLocalGettersCache, | ||
modulePath | ||
); | ||
} | ||
}); | ||
api.on.editInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
var path = payload.path; | ||
if (modulePath !== 'root') { | ||
path = modulePath.split('/').filter(Boolean).concat( path); | ||
} | ||
store._withCommit(function () { | ||
payload.set(store._state.data, path, payload.state.value); | ||
}); | ||
} | ||
}); | ||
store.subscribe(function (mutation, state) { | ||
var data = {}; | ||
if (mutation.payload) { | ||
data.payload = mutation.payload; | ||
} | ||
data.state = state; | ||
api.notifyComponentUpdate(); | ||
api.sendInspectorTree(INSPECTOR_ID); | ||
api.sendInspectorState(INSPECTOR_ID); | ||
api.addTimelineEvent({ | ||
layerId: MUTATIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: mutation.type, | ||
data: data | ||
} | ||
}); | ||
}); | ||
store.subscribeAction({ | ||
before: function (action, state) { | ||
var data = {}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
action._id = actionId++; | ||
action._time = Date.now(); | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: action._time, | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'start', | ||
data: data | ||
} | ||
}); | ||
}, | ||
after: function (action, state) { | ||
var data = {}; | ||
var duration = Date.now() - action._time; | ||
data.duration = { | ||
_custom: { | ||
type: 'duration', | ||
display: (duration + "ms"), | ||
tooltip: 'Action duration', | ||
value: duration | ||
} | ||
}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'end', | ||
data: data | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
// extracted from tailwind palette | ||
var COLOR_LIME_500 = 0x84cc16; | ||
var COLOR_DARK = 0x666666; | ||
var COLOR_WHITE = 0xffffff; | ||
var TAG_NAMESPACED = { | ||
label: 'namespaced', | ||
textColor: COLOR_WHITE, | ||
backgroundColor: COLOR_DARK | ||
}; | ||
/** | ||
* @param {string} path | ||
*/ | ||
function extractNameFromPath (path) { | ||
return path && path !== 'root' ? path.split('/').slice(-2, -1)[0] : 'Root' | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorNode} | ||
*/ | ||
function formatStoreForInspectorTree (module, path) { | ||
return { | ||
id: path || 'root', | ||
// all modules end with a `/`, we want the last segment only | ||
// cart/ -> cart | ||
// nested/cart/ -> cart | ||
label: extractNameFromPath(path), | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [], | ||
children: Object.keys(module._children).map(function (moduleName) { return formatStoreForInspectorTree( | ||
module._children[moduleName], | ||
path + moduleName + '/' | ||
); } | ||
) | ||
} | ||
} | ||
/** | ||
* @param {import('@vue/devtools-api').CustomInspectorNode[]} result | ||
* @param {*} module | ||
* @param {string} filter | ||
* @param {string} path | ||
*/ | ||
function flattenStoreForInspectorTree (result, module, filter, path) { | ||
if (path.includes(filter)) { | ||
result.push({ | ||
id: path || 'root', | ||
label: path.endsWith('/') ? path.slice(0, path.length - 1) : path || 'Root', | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [] | ||
}); | ||
} | ||
Object.keys(module._children).forEach(function (moduleName) { | ||
flattenStoreForInspectorTree(result, module._children[moduleName], filter, path + moduleName + '/'); | ||
}); | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorState} | ||
*/ | ||
function formatStoreForInspectorState (module, getters, path) { | ||
getters = path === 'root' ? getters : getters[path]; | ||
var gettersKeys = Object.keys(getters); | ||
var storeState = { | ||
state: Object.keys(module.state).map(function (key) { return ({ | ||
key: key, | ||
editable: true, | ||
value: module.state[key] | ||
}); }) | ||
}; | ||
if (gettersKeys.length) { | ||
storeState.getters = gettersKeys.map(function (key) { return ({ | ||
key: key.endsWith('/') ? extractNameFromPath(key) : key, | ||
editable: false, | ||
value: getters[key] | ||
}); }); | ||
} | ||
return storeState | ||
} | ||
function getStoreModule (moduleMap, path) { | ||
var names = path.split('/').filter(function (n) { return n; }); | ||
return names.reduce( | ||
function (module, moduleName, i) { | ||
var child = module[moduleName]; | ||
if (!child) { | ||
throw new Error(("Missing module \"" + moduleName + "\" for path \"" + path + "\".")) | ||
} | ||
return i === names.length - 1 ? child : child._children | ||
}, | ||
path === 'root' ? moduleMap : moduleMap.root._children | ||
) | ||
} | ||
// Base data struct for store's module, package with some attribute and method | ||
@@ -136,5 +638,5 @@ var Module = function Module (rawModule, runtime) { | ||
var prototypeAccessors = { namespaced: { configurable: true } }; | ||
var prototypeAccessors$1 = { namespaced: { configurable: true } }; | ||
prototypeAccessors.namespaced.get = function () { | ||
prototypeAccessors$1.namespaced.get = function () { | ||
return !!this._rawModule.namespaced | ||
@@ -194,3 +696,3 @@ }; | ||
Object.defineProperties( Module.prototype, prototypeAccessors ); | ||
Object.defineProperties( Module.prototype, prototypeAccessors$1 ); | ||
@@ -221,3 +723,3 @@ var ModuleCollection = function ModuleCollection (rawRootModule) { | ||
ModuleCollection.prototype.register = function register (path, rawModule, runtime) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( runtime === void 0 ) runtime = true; | ||
@@ -240,3 +742,3 @@ | ||
forEachValue(rawModule.modules, function (rawChildModule, key) { | ||
this$1.register(path.concat(key), rawChildModule, runtime); | ||
this$1$1.register(path.concat(key), rawChildModule, runtime); | ||
}); | ||
@@ -354,3 +856,3 @@ } | ||
var Store = function Store (options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( options === void 0 ) options = {}; | ||
@@ -365,2 +867,3 @@ | ||
var strict = options.strict; if ( strict === void 0 ) strict = false; | ||
var devtools = options.devtools; | ||
@@ -377,2 +880,3 @@ // store internal state | ||
this._makeLocalGettersCache = Object.create(null); | ||
this._devtools = devtools; | ||
@@ -406,11 +910,6 @@ // bind commit and dispatch to self | ||
// apply plugins | ||
plugins.forEach(function (plugin) { return plugin(this$1); }); | ||
var useDevtools = options.devtools !== undefined ? options.devtools : /* Vue.config.devtools */ true; | ||
if (useDevtools) { | ||
devtoolPlugin(this); | ||
} | ||
plugins.forEach(function (plugin) { return plugin(this$1$1); }); | ||
}; | ||
var prototypeAccessors$1 = { state: { configurable: true } }; | ||
var prototypeAccessors = { state: { configurable: true } }; | ||
@@ -420,9 +919,17 @@ Store.prototype.install = function install (app, injectKey) { | ||
app.config.globalProperties.$store = this; | ||
var useDevtools = this._devtools !== undefined | ||
? this._devtools | ||
: (process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__; | ||
if (useDevtools) { | ||
addDevtools(app, this); | ||
} | ||
}; | ||
prototypeAccessors$1.state.get = function () { | ||
prototypeAccessors.state.get = function () { | ||
return this._state.data | ||
}; | ||
prototypeAccessors$1.state.set = function (v) { | ||
prototypeAccessors.state.set = function (v) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
@@ -434,3 +941,3 @@ assert(false, "use store.replaceState() to explicit replace store state."); | ||
Store.prototype.commit = function commit (_type, _payload, _options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -459,3 +966,3 @@ // check object-style commit | ||
.slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe | ||
.forEach(function (sub) { return sub(mutation, this$1.state); }); | ||
.forEach(function (sub) { return sub(mutation, this$1$1.state); }); | ||
@@ -474,3 +981,3 @@ if ( | ||
Store.prototype.dispatch = function dispatch (_type, _payload) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -495,3 +1002,3 @@ // check object-style dispatch | ||
.filter(function (sub) { return sub.before; }) | ||
.forEach(function (sub) { return sub.before(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.before(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -511,5 +1018,5 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.after; }) | ||
.forEach(function (sub) { return sub.after(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.after(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -524,5 +1031,5 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.error; }) | ||
.forEach(function (sub) { return sub.error(action, this$1.state, error); }); | ||
.forEach(function (sub) { return sub.error(action, this$1$1.state, error); }); | ||
} catch (e) { | ||
@@ -549,3 +1056,3 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
Store.prototype.watch = function watch$1 (getter, cb, options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -555,10 +1062,10 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
} | ||
return vue.watch(function () { return getter(this$1.state, this$1.getters); }, cb, Object.assign({}, options)) | ||
return vue.watch(function () { return getter(this$1$1.state, this$1$1.getters); }, cb, Object.assign({}, options)) | ||
}; | ||
Store.prototype.replaceState = function replaceState (state) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
this._withCommit(function () { | ||
this$1._state.data = state; | ||
this$1$1._state.data = state; | ||
}); | ||
@@ -584,3 +1091,3 @@ }; | ||
Store.prototype.unregisterModule = function unregisterModule (path) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -595,3 +1102,3 @@ if (typeof path === 'string') { path = [path]; } | ||
this._withCommit(function () { | ||
var parentState = getNestedState(this$1.state, path.slice(0, -1)); | ||
var parentState = getNestedState(this$1$1.state, path.slice(0, -1)); | ||
delete parentState[path[path.length - 1]]; | ||
@@ -624,283 +1131,5 @@ }); | ||
Object.defineProperties( Store.prototype, prototypeAccessors$1 ); | ||
Object.defineProperties( Store.prototype, prototypeAccessors ); | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = vue.reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && (process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
vue.watch(function () { return store._state.data; }, function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
/** | ||
* Reduce the code which written in Vue.js for getting the state. | ||
@@ -1207,3 +1436,3 @@ * @param {String} [namespace] - Module's namespace | ||
var index_cjs = { | ||
version: '4.0.0', | ||
version: '4.0.1', | ||
Store: Store, | ||
@@ -1210,0 +1439,0 @@ storeKey: storeKey, |
/*! | ||
* vuex v4.0.0 | ||
* vuex v4.0.1 | ||
* (c) 2021 Evan You | ||
* @license MIT | ||
*/ | ||
import { inject, watch, reactive } from 'vue'; | ||
import { inject, reactive, watch } from 'vue'; | ||
import { setupDevtoolsPlugin } from '@vue/devtools-api'; | ||
@@ -16,29 +17,2 @@ var storeKey = 'store'; | ||
var target = typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
var devtoolHook = target.__VUE_DEVTOOLS_GLOBAL_HOOK__; | ||
function devtoolPlugin (store) { | ||
if (!devtoolHook) { return } | ||
store._devtoolHook = devtoolHook; | ||
devtoolHook.emit('vuex:init', store); | ||
devtoolHook.on('vuex:travel-to-state', function (targetState) { | ||
store.replaceState(targetState); | ||
}); | ||
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 }); | ||
} | ||
/** | ||
@@ -119,2 +93,530 @@ * Get the first item that pass the test | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && true) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
{ | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if (!store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if (!store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
{ | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
watch(function () { return store._state.data; }, function () { | ||
{ | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
{ | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
var LABEL_VUEX_BINDINGS = 'vuex bindings'; | ||
var MUTATIONS_LAYER_ID = 'vuex:mutations'; | ||
var ACTIONS_LAYER_ID = 'vuex:actions'; | ||
var INSPECTOR_ID = 'vuex'; | ||
var actionId = 0; | ||
function addDevtools (app, store) { | ||
setupDevtoolsPlugin( | ||
{ | ||
id: 'org.vuejs.vuex', | ||
app: app, | ||
label: 'Vuex', | ||
homepage: 'https://next.vuex.vuejs.org/', | ||
logo: 'https://vuejs.org/images/icons/favicon-96x96.png', | ||
packageName: 'vuex', | ||
componentStateTypes: [LABEL_VUEX_BINDINGS] | ||
}, | ||
function (api) { | ||
api.addTimelineLayer({ | ||
id: MUTATIONS_LAYER_ID, | ||
label: 'Vuex Mutations', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addTimelineLayer({ | ||
id: ACTIONS_LAYER_ID, | ||
label: 'Vuex Actions', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addInspector({ | ||
id: INSPECTOR_ID, | ||
label: 'Vuex', | ||
icon: 'storage', | ||
treeFilterPlaceholder: 'Filter stores...' | ||
}); | ||
api.on.getInspectorTree(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
if (payload.filter) { | ||
var nodes = []; | ||
flattenStoreForInspectorTree(nodes, store._modules.root, payload.filter, ''); | ||
payload.rootNodes = nodes; | ||
} else { | ||
payload.rootNodes = [ | ||
formatStoreForInspectorTree(store._modules.root, '') | ||
]; | ||
} | ||
} | ||
}); | ||
api.on.getInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
makeLocalGetters(store, modulePath); | ||
payload.state = formatStoreForInspectorState( | ||
getStoreModule(store._modules, modulePath), | ||
store._makeLocalGettersCache, | ||
modulePath | ||
); | ||
} | ||
}); | ||
api.on.editInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
var path = payload.path; | ||
if (modulePath !== 'root') { | ||
path = modulePath.split('/').filter(Boolean).concat( path); | ||
} | ||
store._withCommit(function () { | ||
payload.set(store._state.data, path, payload.state.value); | ||
}); | ||
} | ||
}); | ||
store.subscribe(function (mutation, state) { | ||
var data = {}; | ||
if (mutation.payload) { | ||
data.payload = mutation.payload; | ||
} | ||
data.state = state; | ||
api.notifyComponentUpdate(); | ||
api.sendInspectorTree(INSPECTOR_ID); | ||
api.sendInspectorState(INSPECTOR_ID); | ||
api.addTimelineEvent({ | ||
layerId: MUTATIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: mutation.type, | ||
data: data | ||
} | ||
}); | ||
}); | ||
store.subscribeAction({ | ||
before: function (action, state) { | ||
var data = {}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
action._id = actionId++; | ||
action._time = Date.now(); | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: action._time, | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'start', | ||
data: data | ||
} | ||
}); | ||
}, | ||
after: function (action, state) { | ||
var data = {}; | ||
var duration = Date.now() - action._time; | ||
data.duration = { | ||
_custom: { | ||
type: 'duration', | ||
display: (duration + "ms"), | ||
tooltip: 'Action duration', | ||
value: duration | ||
} | ||
}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'end', | ||
data: data | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
// extracted from tailwind palette | ||
var COLOR_LIME_500 = 0x84cc16; | ||
var COLOR_DARK = 0x666666; | ||
var COLOR_WHITE = 0xffffff; | ||
var TAG_NAMESPACED = { | ||
label: 'namespaced', | ||
textColor: COLOR_WHITE, | ||
backgroundColor: COLOR_DARK | ||
}; | ||
/** | ||
* @param {string} path | ||
*/ | ||
function extractNameFromPath (path) { | ||
return path && path !== 'root' ? path.split('/').slice(-2, -1)[0] : 'Root' | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorNode} | ||
*/ | ||
function formatStoreForInspectorTree (module, path) { | ||
return { | ||
id: path || 'root', | ||
// all modules end with a `/`, we want the last segment only | ||
// cart/ -> cart | ||
// nested/cart/ -> cart | ||
label: extractNameFromPath(path), | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [], | ||
children: Object.keys(module._children).map(function (moduleName) { return formatStoreForInspectorTree( | ||
module._children[moduleName], | ||
path + moduleName + '/' | ||
); } | ||
) | ||
} | ||
} | ||
/** | ||
* @param {import('@vue/devtools-api').CustomInspectorNode[]} result | ||
* @param {*} module | ||
* @param {string} filter | ||
* @param {string} path | ||
*/ | ||
function flattenStoreForInspectorTree (result, module, filter, path) { | ||
if (path.includes(filter)) { | ||
result.push({ | ||
id: path || 'root', | ||
label: path.endsWith('/') ? path.slice(0, path.length - 1) : path || 'Root', | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [] | ||
}); | ||
} | ||
Object.keys(module._children).forEach(function (moduleName) { | ||
flattenStoreForInspectorTree(result, module._children[moduleName], filter, path + moduleName + '/'); | ||
}); | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorState} | ||
*/ | ||
function formatStoreForInspectorState (module, getters, path) { | ||
getters = path === 'root' ? getters : getters[path]; | ||
var gettersKeys = Object.keys(getters); | ||
var storeState = { | ||
state: Object.keys(module.state).map(function (key) { return ({ | ||
key: key, | ||
editable: true, | ||
value: module.state[key] | ||
}); }) | ||
}; | ||
if (gettersKeys.length) { | ||
storeState.getters = gettersKeys.map(function (key) { return ({ | ||
key: key.endsWith('/') ? extractNameFromPath(key) : key, | ||
editable: false, | ||
value: getters[key] | ||
}); }); | ||
} | ||
return storeState | ||
} | ||
function getStoreModule (moduleMap, path) { | ||
var names = path.split('/').filter(function (n) { return n; }); | ||
return names.reduce( | ||
function (module, moduleName, i) { | ||
var child = module[moduleName]; | ||
if (!child) { | ||
throw new Error(("Missing module \"" + moduleName + "\" for path \"" + path + "\".")) | ||
} | ||
return i === names.length - 1 ? child : child._children | ||
}, | ||
path === 'root' ? moduleMap : moduleMap.root._children | ||
) | ||
} | ||
// Base data struct for store's module, package with some attribute and method | ||
@@ -133,5 +635,5 @@ var Module = function Module (rawModule, runtime) { | ||
var prototypeAccessors = { namespaced: { configurable: true } }; | ||
var prototypeAccessors$1 = { namespaced: { configurable: true } }; | ||
prototypeAccessors.namespaced.get = function () { | ||
prototypeAccessors$1.namespaced.get = function () { | ||
return !!this._rawModule.namespaced | ||
@@ -191,3 +693,3 @@ }; | ||
Object.defineProperties( Module.prototype, prototypeAccessors ); | ||
Object.defineProperties( Module.prototype, prototypeAccessors$1 ); | ||
@@ -218,3 +720,3 @@ var ModuleCollection = function ModuleCollection (rawRootModule) { | ||
ModuleCollection.prototype.register = function register (path, rawModule, runtime) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( runtime === void 0 ) runtime = true; | ||
@@ -237,3 +739,3 @@ | ||
forEachValue(rawModule.modules, function (rawChildModule, key) { | ||
this$1.register(path.concat(key), rawChildModule, runtime); | ||
this$1$1.register(path.concat(key), rawChildModule, runtime); | ||
}); | ||
@@ -351,3 +853,3 @@ } | ||
var Store = function Store (options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( options === void 0 ) options = {}; | ||
@@ -362,2 +864,3 @@ | ||
var strict = options.strict; if ( strict === void 0 ) strict = false; | ||
var devtools = options.devtools; | ||
@@ -374,2 +877,3 @@ // store internal state | ||
this._makeLocalGettersCache = Object.create(null); | ||
this._devtools = devtools; | ||
@@ -403,11 +907,6 @@ // bind commit and dispatch to self | ||
// apply plugins | ||
plugins.forEach(function (plugin) { return plugin(this$1); }); | ||
var useDevtools = options.devtools !== undefined ? options.devtools : /* Vue.config.devtools */ true; | ||
if (useDevtools) { | ||
devtoolPlugin(this); | ||
} | ||
plugins.forEach(function (plugin) { return plugin(this$1$1); }); | ||
}; | ||
var prototypeAccessors$1 = { state: { configurable: true } }; | ||
var prototypeAccessors = { state: { configurable: true } }; | ||
@@ -417,9 +916,17 @@ Store.prototype.install = function install (app, injectKey) { | ||
app.config.globalProperties.$store = this; | ||
var useDevtools = this._devtools !== undefined | ||
? this._devtools | ||
: true ; | ||
if (useDevtools) { | ||
addDevtools(app, this); | ||
} | ||
}; | ||
prototypeAccessors$1.state.get = function () { | ||
prototypeAccessors.state.get = function () { | ||
return this._state.data | ||
}; | ||
prototypeAccessors$1.state.set = function (v) { | ||
prototypeAccessors.state.set = function (v) { | ||
{ | ||
@@ -431,3 +938,3 @@ assert(false, "use store.replaceState() to explicit replace store state."); | ||
Store.prototype.commit = function commit (_type, _payload, _options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -456,6 +963,5 @@ // check object-style commit | ||
.slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe | ||
.forEach(function (sub) { return sub(mutation, this$1.state); }); | ||
.forEach(function (sub) { return sub(mutation, this$1$1.state); }); | ||
if ( | ||
options && options.silent | ||
@@ -471,3 +977,3 @@ ) { | ||
Store.prototype.dispatch = function dispatch (_type, _payload) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -492,3 +998,3 @@ // check object-style dispatch | ||
.filter(function (sub) { return sub.before; }) | ||
.forEach(function (sub) { return sub.before(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.before(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -508,5 +1014,5 @@ { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.after; }) | ||
.forEach(function (sub) { return sub.after(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.after(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -521,5 +1027,5 @@ { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.error; }) | ||
.forEach(function (sub) { return sub.error(action, this$1.state, error); }); | ||
.forEach(function (sub) { return sub.error(action, this$1$1.state, error); }); | ||
} catch (e) { | ||
@@ -546,3 +1052,3 @@ { | ||
Store.prototype.watch = function watch$1 (getter, cb, options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -552,10 +1058,10 @@ { | ||
} | ||
return watch(function () { return getter(this$1.state, this$1.getters); }, cb, Object.assign({}, options)) | ||
return watch(function () { return getter(this$1$1.state, this$1$1.getters); }, cb, Object.assign({}, options)) | ||
}; | ||
Store.prototype.replaceState = function replaceState (state) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
this._withCommit(function () { | ||
this$1._state.data = state; | ||
this$1$1._state.data = state; | ||
}); | ||
@@ -581,3 +1087,3 @@ }; | ||
Store.prototype.unregisterModule = function unregisterModule (path) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -592,3 +1098,3 @@ if (typeof path === 'string') { path = [path]; } | ||
this._withCommit(function () { | ||
var parentState = getNestedState(this$1.state, path.slice(0, -1)); | ||
var parentState = getNestedState(this$1$1.state, path.slice(0, -1)); | ||
delete parentState[path[path.length - 1]]; | ||
@@ -621,283 +1127,5 @@ }); | ||
Object.defineProperties( Store.prototype, prototypeAccessors$1 ); | ||
Object.defineProperties( Store.prototype, prototypeAccessors ); | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && true) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
{ | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ( !store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ( !store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
{ | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
watch(function () { return store._state.data; }, function () { | ||
{ | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
{ | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
/** | ||
* Reduce the code which written in Vue.js for getting the state. | ||
@@ -910,3 +1138,3 @@ * @param {String} [namespace] - Module's namespace | ||
var res = {}; | ||
if ( !isValidMap(states)) { | ||
if (!isValidMap(states)) { | ||
console.error('[vuex] mapState: mapper parameter must be either an Array or an Object'); | ||
@@ -947,3 +1175,3 @@ } | ||
var res = {}; | ||
if ( !isValidMap(mutations)) { | ||
if (!isValidMap(mutations)) { | ||
console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object'); | ||
@@ -984,3 +1212,3 @@ } | ||
var res = {}; | ||
if ( !isValidMap(getters)) { | ||
if (!isValidMap(getters)) { | ||
console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object'); | ||
@@ -998,3 +1226,3 @@ } | ||
} | ||
if ( !(val in this.$store.getters)) { | ||
if (!(val in this.$store.getters)) { | ||
console.error(("[vuex] unknown getter: " + val)); | ||
@@ -1019,3 +1247,3 @@ return | ||
var res = {}; | ||
if ( !isValidMap(actions)) { | ||
if (!isValidMap(actions)) { | ||
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object'); | ||
@@ -1111,3 +1339,3 @@ } | ||
var module = store._modulesNamespaceMap[namespace]; | ||
if ( !module) { | ||
if (!module) { | ||
console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); | ||
@@ -1210,3 +1438,3 @@ } | ||
var index = { | ||
version: '4.0.0', | ||
version: '4.0.1', | ||
Store: Store, | ||
@@ -1213,0 +1441,0 @@ storeKey: storeKey, |
/*! | ||
* vuex v4.0.0 | ||
* vuex v4.0.1 | ||
* (c) 2021 Evan You | ||
* @license MIT | ||
*/ | ||
import { inject, watch, reactive } from 'vue'; | ||
import { inject, reactive, watch } from 'vue'; | ||
import { setupDevtoolsPlugin } from '@vue/devtools-api'; | ||
@@ -16,29 +17,2 @@ var storeKey = 'store'; | ||
var target = typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
var devtoolHook = target.__VUE_DEVTOOLS_GLOBAL_HOOK__; | ||
function devtoolPlugin (store) { | ||
if (!devtoolHook) { return } | ||
store._devtoolHook = devtoolHook; | ||
devtoolHook.emit('vuex:init', store); | ||
devtoolHook.on('vuex:travel-to-state', function (targetState) { | ||
store.replaceState(targetState); | ||
}); | ||
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 }); | ||
} | ||
/** | ||
@@ -115,2 +89,505 @@ * Get the first item that pass the test | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && false) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
watch(function () { return store._state.data; }, function () { | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
var LABEL_VUEX_BINDINGS = 'vuex bindings'; | ||
var MUTATIONS_LAYER_ID = 'vuex:mutations'; | ||
var ACTIONS_LAYER_ID = 'vuex:actions'; | ||
var INSPECTOR_ID = 'vuex'; | ||
var actionId = 0; | ||
function addDevtools (app, store) { | ||
setupDevtoolsPlugin( | ||
{ | ||
id: 'org.vuejs.vuex', | ||
app: app, | ||
label: 'Vuex', | ||
homepage: 'https://next.vuex.vuejs.org/', | ||
logo: 'https://vuejs.org/images/icons/favicon-96x96.png', | ||
packageName: 'vuex', | ||
componentStateTypes: [LABEL_VUEX_BINDINGS] | ||
}, | ||
function (api) { | ||
api.addTimelineLayer({ | ||
id: MUTATIONS_LAYER_ID, | ||
label: 'Vuex Mutations', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addTimelineLayer({ | ||
id: ACTIONS_LAYER_ID, | ||
label: 'Vuex Actions', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addInspector({ | ||
id: INSPECTOR_ID, | ||
label: 'Vuex', | ||
icon: 'storage', | ||
treeFilterPlaceholder: 'Filter stores...' | ||
}); | ||
api.on.getInspectorTree(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
if (payload.filter) { | ||
var nodes = []; | ||
flattenStoreForInspectorTree(nodes, store._modules.root, payload.filter, ''); | ||
payload.rootNodes = nodes; | ||
} else { | ||
payload.rootNodes = [ | ||
formatStoreForInspectorTree(store._modules.root, '') | ||
]; | ||
} | ||
} | ||
}); | ||
api.on.getInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
makeLocalGetters(store, modulePath); | ||
payload.state = formatStoreForInspectorState( | ||
getStoreModule(store._modules, modulePath), | ||
store._makeLocalGettersCache, | ||
modulePath | ||
); | ||
} | ||
}); | ||
api.on.editInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
var path = payload.path; | ||
if (modulePath !== 'root') { | ||
path = modulePath.split('/').filter(Boolean).concat( path); | ||
} | ||
store._withCommit(function () { | ||
payload.set(store._state.data, path, payload.state.value); | ||
}); | ||
} | ||
}); | ||
store.subscribe(function (mutation, state) { | ||
var data = {}; | ||
if (mutation.payload) { | ||
data.payload = mutation.payload; | ||
} | ||
data.state = state; | ||
api.notifyComponentUpdate(); | ||
api.sendInspectorTree(INSPECTOR_ID); | ||
api.sendInspectorState(INSPECTOR_ID); | ||
api.addTimelineEvent({ | ||
layerId: MUTATIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: mutation.type, | ||
data: data | ||
} | ||
}); | ||
}); | ||
store.subscribeAction({ | ||
before: function (action, state) { | ||
var data = {}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
action._id = actionId++; | ||
action._time = Date.now(); | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: action._time, | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'start', | ||
data: data | ||
} | ||
}); | ||
}, | ||
after: function (action, state) { | ||
var data = {}; | ||
var duration = Date.now() - action._time; | ||
data.duration = { | ||
_custom: { | ||
type: 'duration', | ||
display: (duration + "ms"), | ||
tooltip: 'Action duration', | ||
value: duration | ||
} | ||
}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'end', | ||
data: data | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
// extracted from tailwind palette | ||
var COLOR_LIME_500 = 0x84cc16; | ||
var COLOR_DARK = 0x666666; | ||
var COLOR_WHITE = 0xffffff; | ||
var TAG_NAMESPACED = { | ||
label: 'namespaced', | ||
textColor: COLOR_WHITE, | ||
backgroundColor: COLOR_DARK | ||
}; | ||
/** | ||
* @param {string} path | ||
*/ | ||
function extractNameFromPath (path) { | ||
return path && path !== 'root' ? path.split('/').slice(-2, -1)[0] : 'Root' | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorNode} | ||
*/ | ||
function formatStoreForInspectorTree (module, path) { | ||
return { | ||
id: path || 'root', | ||
// all modules end with a `/`, we want the last segment only | ||
// cart/ -> cart | ||
// nested/cart/ -> cart | ||
label: extractNameFromPath(path), | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [], | ||
children: Object.keys(module._children).map(function (moduleName) { return formatStoreForInspectorTree( | ||
module._children[moduleName], | ||
path + moduleName + '/' | ||
); } | ||
) | ||
} | ||
} | ||
/** | ||
* @param {import('@vue/devtools-api').CustomInspectorNode[]} result | ||
* @param {*} module | ||
* @param {string} filter | ||
* @param {string} path | ||
*/ | ||
function flattenStoreForInspectorTree (result, module, filter, path) { | ||
if (path.includes(filter)) { | ||
result.push({ | ||
id: path || 'root', | ||
label: path.endsWith('/') ? path.slice(0, path.length - 1) : path || 'Root', | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [] | ||
}); | ||
} | ||
Object.keys(module._children).forEach(function (moduleName) { | ||
flattenStoreForInspectorTree(result, module._children[moduleName], filter, path + moduleName + '/'); | ||
}); | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorState} | ||
*/ | ||
function formatStoreForInspectorState (module, getters, path) { | ||
getters = path === 'root' ? getters : getters[path]; | ||
var gettersKeys = Object.keys(getters); | ||
var storeState = { | ||
state: Object.keys(module.state).map(function (key) { return ({ | ||
key: key, | ||
editable: true, | ||
value: module.state[key] | ||
}); }) | ||
}; | ||
if (gettersKeys.length) { | ||
storeState.getters = gettersKeys.map(function (key) { return ({ | ||
key: key.endsWith('/') ? extractNameFromPath(key) : key, | ||
editable: false, | ||
value: getters[key] | ||
}); }); | ||
} | ||
return storeState | ||
} | ||
function getStoreModule (moduleMap, path) { | ||
var names = path.split('/').filter(function (n) { return n; }); | ||
return names.reduce( | ||
function (module, moduleName, i) { | ||
var child = module[moduleName]; | ||
if (!child) { | ||
throw new Error(("Missing module \"" + moduleName + "\" for path \"" + path + "\".")) | ||
} | ||
return i === names.length - 1 ? child : child._children | ||
}, | ||
path === 'root' ? moduleMap : moduleMap.root._children | ||
) | ||
} | ||
// Base data struct for store's module, package with some attribute and method | ||
@@ -129,5 +606,5 @@ var Module = function Module (rawModule, runtime) { | ||
var prototypeAccessors = { namespaced: { configurable: true } }; | ||
var prototypeAccessors$1 = { namespaced: { configurable: true } }; | ||
prototypeAccessors.namespaced.get = function () { | ||
prototypeAccessors$1.namespaced.get = function () { | ||
return !!this._rawModule.namespaced | ||
@@ -187,3 +664,3 @@ }; | ||
Object.defineProperties( Module.prototype, prototypeAccessors ); | ||
Object.defineProperties( Module.prototype, prototypeAccessors$1 ); | ||
@@ -214,3 +691,3 @@ var ModuleCollection = function ModuleCollection (rawRootModule) { | ||
ModuleCollection.prototype.register = function register (path, rawModule, runtime) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( runtime === void 0 ) runtime = true; | ||
@@ -229,3 +706,3 @@ | ||
forEachValue(rawModule.modules, function (rawChildModule, key) { | ||
this$1.register(path.concat(key), rawChildModule, runtime); | ||
this$1$1.register(path.concat(key), rawChildModule, runtime); | ||
}); | ||
@@ -287,3 +764,3 @@ } | ||
var Store = function Store (options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( options === void 0 ) options = {}; | ||
@@ -293,2 +770,3 @@ | ||
var strict = options.strict; if ( strict === void 0 ) strict = false; | ||
var devtools = options.devtools; | ||
@@ -305,2 +783,3 @@ // store internal state | ||
this._makeLocalGettersCache = Object.create(null); | ||
this._devtools = devtools; | ||
@@ -334,11 +813,6 @@ // bind commit and dispatch to self | ||
// apply plugins | ||
plugins.forEach(function (plugin) { return plugin(this$1); }); | ||
var useDevtools = options.devtools !== undefined ? options.devtools : /* Vue.config.devtools */ true; | ||
if (useDevtools) { | ||
devtoolPlugin(this); | ||
} | ||
plugins.forEach(function (plugin) { return plugin(this$1$1); }); | ||
}; | ||
var prototypeAccessors$1 = { state: { configurable: true } }; | ||
var prototypeAccessors = { state: { configurable: true } }; | ||
@@ -348,13 +822,21 @@ Store.prototype.install = function install (app, injectKey) { | ||
app.config.globalProperties.$store = this; | ||
var useDevtools = this._devtools !== undefined | ||
? this._devtools | ||
: false; | ||
if (useDevtools) { | ||
addDevtools(app, this); | ||
} | ||
}; | ||
prototypeAccessors$1.state.get = function () { | ||
prototypeAccessors.state.get = function () { | ||
return this._state.data | ||
}; | ||
prototypeAccessors$1.state.set = function (v) { | ||
prototypeAccessors.state.set = function (v) { | ||
}; | ||
Store.prototype.commit = function commit (_type, _payload, _options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -379,7 +861,7 @@ // check object-style commit | ||
.slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe | ||
.forEach(function (sub) { return sub(mutation, this$1.state); }); | ||
.forEach(function (sub) { return sub(mutation, this$1$1.state); }); | ||
}; | ||
Store.prototype.dispatch = function dispatch (_type, _payload) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -401,3 +883,3 @@ // check object-style dispatch | ||
.filter(function (sub) { return sub.before; }) | ||
.forEach(function (sub) { return sub.before(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.before(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -413,5 +895,5 @@ } | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.after; }) | ||
.forEach(function (sub) { return sub.after(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.after(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -422,5 +904,5 @@ } | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.error; }) | ||
.forEach(function (sub) { return sub.error(action, this$1.state, error); }); | ||
.forEach(function (sub) { return sub.error(action, this$1$1.state, error); }); | ||
} catch (e) { | ||
@@ -443,11 +925,11 @@ } | ||
Store.prototype.watch = function watch$1 (getter, cb, options) { | ||
var this$1 = this; | ||
return watch(function () { return getter(this$1.state, this$1.getters); }, cb, Object.assign({}, options)) | ||
var this$1$1 = this; | ||
return watch(function () { return getter(this$1$1.state, this$1$1.getters); }, cb, Object.assign({}, options)) | ||
}; | ||
Store.prototype.replaceState = function replaceState (state) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
this._withCommit(function () { | ||
this$1._state.data = state; | ||
this$1$1._state.data = state; | ||
}); | ||
@@ -468,3 +950,3 @@ }; | ||
Store.prototype.unregisterModule = function unregisterModule (path) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -475,3 +957,3 @@ if (typeof path === 'string') { path = [path]; } | ||
this._withCommit(function () { | ||
var parentState = getNestedState(this$1.state, path.slice(0, -1)); | ||
var parentState = getNestedState(this$1$1.state, path.slice(0, -1)); | ||
delete parentState[path[path.length - 1]]; | ||
@@ -500,258 +982,5 @@ }); | ||
Object.defineProperties( Store.prototype, prototypeAccessors$1 ); | ||
Object.defineProperties( Store.prototype, prototypeAccessors ); | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && false) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
watch(function () { return store._state.data; }, function () { | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
/** | ||
* Reduce the code which written in Vue.js for getting the state. | ||
@@ -1039,3 +1268,3 @@ * @param {String} [namespace] - Module's namespace | ||
var index = { | ||
version: '4.0.0', | ||
version: '4.0.1', | ||
Store: Store, | ||
@@ -1042,0 +1271,0 @@ storeKey: storeKey, |
/*! | ||
* vuex v4.0.0 | ||
* vuex v4.0.1 | ||
* (c) 2021 Evan You | ||
* @license MIT | ||
*/ | ||
import { inject, watch, reactive } from 'vue'; | ||
import { inject, reactive, watch } from 'vue'; | ||
import { setupDevtoolsPlugin } from '@vue/devtools-api'; | ||
@@ -16,29 +17,2 @@ var storeKey = 'store'; | ||
var target = typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
var devtoolHook = target.__VUE_DEVTOOLS_GLOBAL_HOOK__; | ||
function devtoolPlugin (store) { | ||
if (!devtoolHook) { return } | ||
store._devtoolHook = devtoolHook; | ||
devtoolHook.emit('vuex:init', store); | ||
devtoolHook.on('vuex:travel-to-state', function (targetState) { | ||
store.replaceState(targetState); | ||
}); | ||
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 }); | ||
} | ||
/** | ||
@@ -119,2 +93,530 @@ * Get the first item that pass the test | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && (process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
watch(function () { return store._state.data; }, function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
var LABEL_VUEX_BINDINGS = 'vuex bindings'; | ||
var MUTATIONS_LAYER_ID = 'vuex:mutations'; | ||
var ACTIONS_LAYER_ID = 'vuex:actions'; | ||
var INSPECTOR_ID = 'vuex'; | ||
var actionId = 0; | ||
function addDevtools (app, store) { | ||
setupDevtoolsPlugin( | ||
{ | ||
id: 'org.vuejs.vuex', | ||
app: app, | ||
label: 'Vuex', | ||
homepage: 'https://next.vuex.vuejs.org/', | ||
logo: 'https://vuejs.org/images/icons/favicon-96x96.png', | ||
packageName: 'vuex', | ||
componentStateTypes: [LABEL_VUEX_BINDINGS] | ||
}, | ||
function (api) { | ||
api.addTimelineLayer({ | ||
id: MUTATIONS_LAYER_ID, | ||
label: 'Vuex Mutations', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addTimelineLayer({ | ||
id: ACTIONS_LAYER_ID, | ||
label: 'Vuex Actions', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addInspector({ | ||
id: INSPECTOR_ID, | ||
label: 'Vuex', | ||
icon: 'storage', | ||
treeFilterPlaceholder: 'Filter stores...' | ||
}); | ||
api.on.getInspectorTree(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
if (payload.filter) { | ||
var nodes = []; | ||
flattenStoreForInspectorTree(nodes, store._modules.root, payload.filter, ''); | ||
payload.rootNodes = nodes; | ||
} else { | ||
payload.rootNodes = [ | ||
formatStoreForInspectorTree(store._modules.root, '') | ||
]; | ||
} | ||
} | ||
}); | ||
api.on.getInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
makeLocalGetters(store, modulePath); | ||
payload.state = formatStoreForInspectorState( | ||
getStoreModule(store._modules, modulePath), | ||
store._makeLocalGettersCache, | ||
modulePath | ||
); | ||
} | ||
}); | ||
api.on.editInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
var path = payload.path; | ||
if (modulePath !== 'root') { | ||
path = modulePath.split('/').filter(Boolean).concat( path); | ||
} | ||
store._withCommit(function () { | ||
payload.set(store._state.data, path, payload.state.value); | ||
}); | ||
} | ||
}); | ||
store.subscribe(function (mutation, state) { | ||
var data = {}; | ||
if (mutation.payload) { | ||
data.payload = mutation.payload; | ||
} | ||
data.state = state; | ||
api.notifyComponentUpdate(); | ||
api.sendInspectorTree(INSPECTOR_ID); | ||
api.sendInspectorState(INSPECTOR_ID); | ||
api.addTimelineEvent({ | ||
layerId: MUTATIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: mutation.type, | ||
data: data | ||
} | ||
}); | ||
}); | ||
store.subscribeAction({ | ||
before: function (action, state) { | ||
var data = {}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
action._id = actionId++; | ||
action._time = Date.now(); | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: action._time, | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'start', | ||
data: data | ||
} | ||
}); | ||
}, | ||
after: function (action, state) { | ||
var data = {}; | ||
var duration = Date.now() - action._time; | ||
data.duration = { | ||
_custom: { | ||
type: 'duration', | ||
display: (duration + "ms"), | ||
tooltip: 'Action duration', | ||
value: duration | ||
} | ||
}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'end', | ||
data: data | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
// extracted from tailwind palette | ||
var COLOR_LIME_500 = 0x84cc16; | ||
var COLOR_DARK = 0x666666; | ||
var COLOR_WHITE = 0xffffff; | ||
var TAG_NAMESPACED = { | ||
label: 'namespaced', | ||
textColor: COLOR_WHITE, | ||
backgroundColor: COLOR_DARK | ||
}; | ||
/** | ||
* @param {string} path | ||
*/ | ||
function extractNameFromPath (path) { | ||
return path && path !== 'root' ? path.split('/').slice(-2, -1)[0] : 'Root' | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorNode} | ||
*/ | ||
function formatStoreForInspectorTree (module, path) { | ||
return { | ||
id: path || 'root', | ||
// all modules end with a `/`, we want the last segment only | ||
// cart/ -> cart | ||
// nested/cart/ -> cart | ||
label: extractNameFromPath(path), | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [], | ||
children: Object.keys(module._children).map(function (moduleName) { return formatStoreForInspectorTree( | ||
module._children[moduleName], | ||
path + moduleName + '/' | ||
); } | ||
) | ||
} | ||
} | ||
/** | ||
* @param {import('@vue/devtools-api').CustomInspectorNode[]} result | ||
* @param {*} module | ||
* @param {string} filter | ||
* @param {string} path | ||
*/ | ||
function flattenStoreForInspectorTree (result, module, filter, path) { | ||
if (path.includes(filter)) { | ||
result.push({ | ||
id: path || 'root', | ||
label: path.endsWith('/') ? path.slice(0, path.length - 1) : path || 'Root', | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [] | ||
}); | ||
} | ||
Object.keys(module._children).forEach(function (moduleName) { | ||
flattenStoreForInspectorTree(result, module._children[moduleName], filter, path + moduleName + '/'); | ||
}); | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorState} | ||
*/ | ||
function formatStoreForInspectorState (module, getters, path) { | ||
getters = path === 'root' ? getters : getters[path]; | ||
var gettersKeys = Object.keys(getters); | ||
var storeState = { | ||
state: Object.keys(module.state).map(function (key) { return ({ | ||
key: key, | ||
editable: true, | ||
value: module.state[key] | ||
}); }) | ||
}; | ||
if (gettersKeys.length) { | ||
storeState.getters = gettersKeys.map(function (key) { return ({ | ||
key: key.endsWith('/') ? extractNameFromPath(key) : key, | ||
editable: false, | ||
value: getters[key] | ||
}); }); | ||
} | ||
return storeState | ||
} | ||
function getStoreModule (moduleMap, path) { | ||
var names = path.split('/').filter(function (n) { return n; }); | ||
return names.reduce( | ||
function (module, moduleName, i) { | ||
var child = module[moduleName]; | ||
if (!child) { | ||
throw new Error(("Missing module \"" + moduleName + "\" for path \"" + path + "\".")) | ||
} | ||
return i === names.length - 1 ? child : child._children | ||
}, | ||
path === 'root' ? moduleMap : moduleMap.root._children | ||
) | ||
} | ||
// Base data struct for store's module, package with some attribute and method | ||
@@ -133,5 +635,5 @@ var Module = function Module (rawModule, runtime) { | ||
var prototypeAccessors = { namespaced: { configurable: true } }; | ||
var prototypeAccessors$1 = { namespaced: { configurable: true } }; | ||
prototypeAccessors.namespaced.get = function () { | ||
prototypeAccessors$1.namespaced.get = function () { | ||
return !!this._rawModule.namespaced | ||
@@ -191,3 +693,3 @@ }; | ||
Object.defineProperties( Module.prototype, prototypeAccessors ); | ||
Object.defineProperties( Module.prototype, prototypeAccessors$1 ); | ||
@@ -218,3 +720,3 @@ var ModuleCollection = function ModuleCollection (rawRootModule) { | ||
ModuleCollection.prototype.register = function register (path, rawModule, runtime) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( runtime === void 0 ) runtime = true; | ||
@@ -237,3 +739,3 @@ | ||
forEachValue(rawModule.modules, function (rawChildModule, key) { | ||
this$1.register(path.concat(key), rawChildModule, runtime); | ||
this$1$1.register(path.concat(key), rawChildModule, runtime); | ||
}); | ||
@@ -351,3 +853,3 @@ } | ||
var Store = function Store (options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( options === void 0 ) options = {}; | ||
@@ -362,2 +864,3 @@ | ||
var strict = options.strict; if ( strict === void 0 ) strict = false; | ||
var devtools = options.devtools; | ||
@@ -374,2 +877,3 @@ // store internal state | ||
this._makeLocalGettersCache = Object.create(null); | ||
this._devtools = devtools; | ||
@@ -403,11 +907,6 @@ // bind commit and dispatch to self | ||
// apply plugins | ||
plugins.forEach(function (plugin) { return plugin(this$1); }); | ||
var useDevtools = options.devtools !== undefined ? options.devtools : /* Vue.config.devtools */ true; | ||
if (useDevtools) { | ||
devtoolPlugin(this); | ||
} | ||
plugins.forEach(function (plugin) { return plugin(this$1$1); }); | ||
}; | ||
var prototypeAccessors$1 = { state: { configurable: true } }; | ||
var prototypeAccessors = { state: { configurable: true } }; | ||
@@ -417,9 +916,17 @@ Store.prototype.install = function install (app, injectKey) { | ||
app.config.globalProperties.$store = this; | ||
var useDevtools = this._devtools !== undefined | ||
? this._devtools | ||
: (process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__; | ||
if (useDevtools) { | ||
addDevtools(app, this); | ||
} | ||
}; | ||
prototypeAccessors$1.state.get = function () { | ||
prototypeAccessors.state.get = function () { | ||
return this._state.data | ||
}; | ||
prototypeAccessors$1.state.set = function (v) { | ||
prototypeAccessors.state.set = function (v) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
@@ -431,3 +938,3 @@ assert(false, "use store.replaceState() to explicit replace store state."); | ||
Store.prototype.commit = function commit (_type, _payload, _options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -456,3 +963,3 @@ // check object-style commit | ||
.slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe | ||
.forEach(function (sub) { return sub(mutation, this$1.state); }); | ||
.forEach(function (sub) { return sub(mutation, this$1$1.state); }); | ||
@@ -471,3 +978,3 @@ if ( | ||
Store.prototype.dispatch = function dispatch (_type, _payload) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -492,3 +999,3 @@ // check object-style dispatch | ||
.filter(function (sub) { return sub.before; }) | ||
.forEach(function (sub) { return sub.before(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.before(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -508,5 +1015,5 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.after; }) | ||
.forEach(function (sub) { return sub.after(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.after(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -521,5 +1028,5 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.error; }) | ||
.forEach(function (sub) { return sub.error(action, this$1.state, error); }); | ||
.forEach(function (sub) { return sub.error(action, this$1$1.state, error); }); | ||
} catch (e) { | ||
@@ -546,3 +1053,3 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
Store.prototype.watch = function watch$1 (getter, cb, options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -552,10 +1059,10 @@ if ((process.env.NODE_ENV !== 'production')) { | ||
} | ||
return watch(function () { return getter(this$1.state, this$1.getters); }, cb, Object.assign({}, options)) | ||
return watch(function () { return getter(this$1$1.state, this$1$1.getters); }, cb, Object.assign({}, options)) | ||
}; | ||
Store.prototype.replaceState = function replaceState (state) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
this._withCommit(function () { | ||
this$1._state.data = state; | ||
this$1$1._state.data = state; | ||
}); | ||
@@ -581,3 +1088,3 @@ }; | ||
Store.prototype.unregisterModule = function unregisterModule (path) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -592,3 +1099,3 @@ if (typeof path === 'string') { path = [path]; } | ||
this._withCommit(function () { | ||
var parentState = getNestedState(this$1.state, path.slice(0, -1)); | ||
var parentState = getNestedState(this$1$1.state, path.slice(0, -1)); | ||
delete parentState[path[path.length - 1]]; | ||
@@ -621,283 +1128,5 @@ }); | ||
Object.defineProperties( Store.prototype, prototypeAccessors$1 ); | ||
Object.defineProperties( Store.prototype, prototypeAccessors ); | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && (process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ((process.env.NODE_ENV !== 'production') && !store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
watch(function () { return store._state.data; }, function () { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
/** | ||
* Reduce the code which written in Vue.js for getting the state. | ||
@@ -1204,3 +1433,3 @@ * @param {String} [namespace] - Module's namespace | ||
var index = { | ||
version: '4.0.0', | ||
version: '4.0.1', | ||
Store: Store, | ||
@@ -1207,0 +1436,0 @@ storeKey: storeKey, |
/*! | ||
* vuex v4.0.0 | ||
* vuex v4.0.1 | ||
* (c) 2021 Evan You | ||
@@ -17,27 +17,29 @@ * @license MIT | ||
var target = typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
var devtoolHook = target.__VUE_DEVTOOLS_GLOBAL_HOOK__; | ||
function getDevtoolsGlobalHook() { | ||
return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__; | ||
} | ||
function getTarget() { | ||
// @ts-ignore | ||
return typeof navigator !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
} | ||
function devtoolPlugin (store) { | ||
if (!devtoolHook) { return } | ||
var HOOK_SETUP = 'devtools-plugin:setup'; | ||
store._devtoolHook = devtoolHook; | ||
devtoolHook.emit('vuex:init', store); | ||
devtoolHook.on('vuex:travel-to-state', function (targetState) { | ||
store.replaceState(targetState); | ||
}); | ||
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 }); | ||
function setupDevtoolsPlugin(pluginDescriptor, setupFn) { | ||
var hook = getDevtoolsGlobalHook(); | ||
if (hook) { | ||
hook.emit(HOOK_SETUP, pluginDescriptor, setupFn); | ||
} | ||
else { | ||
var target = getTarget(); | ||
var list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || []; | ||
list.push({ | ||
pluginDescriptor: pluginDescriptor, | ||
setupFn: setupFn | ||
}); | ||
} | ||
} | ||
@@ -120,2 +122,530 @@ | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = vue.reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && true) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
{ | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if (!store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if (!store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
{ | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
vue.watch(function () { return store._state.data; }, function () { | ||
{ | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
{ | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
var LABEL_VUEX_BINDINGS = 'vuex bindings'; | ||
var MUTATIONS_LAYER_ID = 'vuex:mutations'; | ||
var ACTIONS_LAYER_ID = 'vuex:actions'; | ||
var INSPECTOR_ID = 'vuex'; | ||
var actionId = 0; | ||
function addDevtools (app, store) { | ||
setupDevtoolsPlugin( | ||
{ | ||
id: 'org.vuejs.vuex', | ||
app: app, | ||
label: 'Vuex', | ||
homepage: 'https://next.vuex.vuejs.org/', | ||
logo: 'https://vuejs.org/images/icons/favicon-96x96.png', | ||
packageName: 'vuex', | ||
componentStateTypes: [LABEL_VUEX_BINDINGS] | ||
}, | ||
function (api) { | ||
api.addTimelineLayer({ | ||
id: MUTATIONS_LAYER_ID, | ||
label: 'Vuex Mutations', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addTimelineLayer({ | ||
id: ACTIONS_LAYER_ID, | ||
label: 'Vuex Actions', | ||
color: COLOR_LIME_500 | ||
}); | ||
api.addInspector({ | ||
id: INSPECTOR_ID, | ||
label: 'Vuex', | ||
icon: 'storage', | ||
treeFilterPlaceholder: 'Filter stores...' | ||
}); | ||
api.on.getInspectorTree(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
if (payload.filter) { | ||
var nodes = []; | ||
flattenStoreForInspectorTree(nodes, store._modules.root, payload.filter, ''); | ||
payload.rootNodes = nodes; | ||
} else { | ||
payload.rootNodes = [ | ||
formatStoreForInspectorTree(store._modules.root, '') | ||
]; | ||
} | ||
} | ||
}); | ||
api.on.getInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
makeLocalGetters(store, modulePath); | ||
payload.state = formatStoreForInspectorState( | ||
getStoreModule(store._modules, modulePath), | ||
store._makeLocalGettersCache, | ||
modulePath | ||
); | ||
} | ||
}); | ||
api.on.editInspectorState(function (payload) { | ||
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) { | ||
var modulePath = payload.nodeId; | ||
var path = payload.path; | ||
if (modulePath !== 'root') { | ||
path = modulePath.split('/').filter(Boolean).concat( path); | ||
} | ||
store._withCommit(function () { | ||
payload.set(store._state.data, path, payload.state.value); | ||
}); | ||
} | ||
}); | ||
store.subscribe(function (mutation, state) { | ||
var data = {}; | ||
if (mutation.payload) { | ||
data.payload = mutation.payload; | ||
} | ||
data.state = state; | ||
api.notifyComponentUpdate(); | ||
api.sendInspectorTree(INSPECTOR_ID); | ||
api.sendInspectorState(INSPECTOR_ID); | ||
api.addTimelineEvent({ | ||
layerId: MUTATIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: mutation.type, | ||
data: data | ||
} | ||
}); | ||
}); | ||
store.subscribeAction({ | ||
before: function (action, state) { | ||
var data = {}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
action._id = actionId++; | ||
action._time = Date.now(); | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: action._time, | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'start', | ||
data: data | ||
} | ||
}); | ||
}, | ||
after: function (action, state) { | ||
var data = {}; | ||
var duration = Date.now() - action._time; | ||
data.duration = { | ||
_custom: { | ||
type: 'duration', | ||
display: (duration + "ms"), | ||
tooltip: 'Action duration', | ||
value: duration | ||
} | ||
}; | ||
if (action.payload) { | ||
data.payload = action.payload; | ||
} | ||
data.state = state; | ||
api.addTimelineEvent({ | ||
layerId: ACTIONS_LAYER_ID, | ||
event: { | ||
time: Date.now(), | ||
title: action.type, | ||
groupId: action._id, | ||
subtitle: 'end', | ||
data: data | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
// extracted from tailwind palette | ||
var COLOR_LIME_500 = 0x84cc16; | ||
var COLOR_DARK = 0x666666; | ||
var COLOR_WHITE = 0xffffff; | ||
var TAG_NAMESPACED = { | ||
label: 'namespaced', | ||
textColor: COLOR_WHITE, | ||
backgroundColor: COLOR_DARK | ||
}; | ||
/** | ||
* @param {string} path | ||
*/ | ||
function extractNameFromPath (path) { | ||
return path && path !== 'root' ? path.split('/').slice(-2, -1)[0] : 'Root' | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorNode} | ||
*/ | ||
function formatStoreForInspectorTree (module, path) { | ||
return { | ||
id: path || 'root', | ||
// all modules end with a `/`, we want the last segment only | ||
// cart/ -> cart | ||
// nested/cart/ -> cart | ||
label: extractNameFromPath(path), | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [], | ||
children: Object.keys(module._children).map(function (moduleName) { return formatStoreForInspectorTree( | ||
module._children[moduleName], | ||
path + moduleName + '/' | ||
); } | ||
) | ||
} | ||
} | ||
/** | ||
* @param {import('@vue/devtools-api').CustomInspectorNode[]} result | ||
* @param {*} module | ||
* @param {string} filter | ||
* @param {string} path | ||
*/ | ||
function flattenStoreForInspectorTree (result, module, filter, path) { | ||
if (path.includes(filter)) { | ||
result.push({ | ||
id: path || 'root', | ||
label: path.endsWith('/') ? path.slice(0, path.length - 1) : path || 'Root', | ||
tags: module.namespaced ? [TAG_NAMESPACED] : [] | ||
}); | ||
} | ||
Object.keys(module._children).forEach(function (moduleName) { | ||
flattenStoreForInspectorTree(result, module._children[moduleName], filter, path + moduleName + '/'); | ||
}); | ||
} | ||
/** | ||
* @param {*} module | ||
* @return {import('@vue/devtools-api').CustomInspectorState} | ||
*/ | ||
function formatStoreForInspectorState (module, getters, path) { | ||
getters = path === 'root' ? getters : getters[path]; | ||
var gettersKeys = Object.keys(getters); | ||
var storeState = { | ||
state: Object.keys(module.state).map(function (key) { return ({ | ||
key: key, | ||
editable: true, | ||
value: module.state[key] | ||
}); }) | ||
}; | ||
if (gettersKeys.length) { | ||
storeState.getters = gettersKeys.map(function (key) { return ({ | ||
key: key.endsWith('/') ? extractNameFromPath(key) : key, | ||
editable: false, | ||
value: getters[key] | ||
}); }); | ||
} | ||
return storeState | ||
} | ||
function getStoreModule (moduleMap, path) { | ||
var names = path.split('/').filter(function (n) { return n; }); | ||
return names.reduce( | ||
function (module, moduleName, i) { | ||
var child = module[moduleName]; | ||
if (!child) { | ||
throw new Error(("Missing module \"" + moduleName + "\" for path \"" + path + "\".")) | ||
} | ||
return i === names.length - 1 ? child : child._children | ||
}, | ||
path === 'root' ? moduleMap : moduleMap.root._children | ||
) | ||
} | ||
// Base data struct for store's module, package with some attribute and method | ||
@@ -134,5 +664,5 @@ var Module = function Module (rawModule, runtime) { | ||
var prototypeAccessors = { namespaced: { configurable: true } }; | ||
var prototypeAccessors$1 = { namespaced: { configurable: true } }; | ||
prototypeAccessors.namespaced.get = function () { | ||
prototypeAccessors$1.namespaced.get = function () { | ||
return !!this._rawModule.namespaced | ||
@@ -192,3 +722,3 @@ }; | ||
Object.defineProperties( Module.prototype, prototypeAccessors ); | ||
Object.defineProperties( Module.prototype, prototypeAccessors$1 ); | ||
@@ -219,3 +749,3 @@ var ModuleCollection = function ModuleCollection (rawRootModule) { | ||
ModuleCollection.prototype.register = function register (path, rawModule, runtime) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( runtime === void 0 ) runtime = true; | ||
@@ -238,3 +768,3 @@ | ||
forEachValue(rawModule.modules, function (rawChildModule, key) { | ||
this$1.register(path.concat(key), rawChildModule, runtime); | ||
this$1$1.register(path.concat(key), rawChildModule, runtime); | ||
}); | ||
@@ -352,3 +882,3 @@ } | ||
var Store = function Store (options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
if ( options === void 0 ) options = {}; | ||
@@ -363,2 +893,3 @@ | ||
var strict = options.strict; if ( strict === void 0 ) strict = false; | ||
var devtools = options.devtools; | ||
@@ -375,2 +906,3 @@ // store internal state | ||
this._makeLocalGettersCache = Object.create(null); | ||
this._devtools = devtools; | ||
@@ -404,11 +936,6 @@ // bind commit and dispatch to self | ||
// apply plugins | ||
plugins.forEach(function (plugin) { return plugin(this$1); }); | ||
var useDevtools = options.devtools !== undefined ? options.devtools : /* Vue.config.devtools */ true; | ||
if (useDevtools) { | ||
devtoolPlugin(this); | ||
} | ||
plugins.forEach(function (plugin) { return plugin(this$1$1); }); | ||
}; | ||
var prototypeAccessors$1 = { state: { configurable: true } }; | ||
var prototypeAccessors = { state: { configurable: true } }; | ||
@@ -418,9 +945,17 @@ Store.prototype.install = function install (app, injectKey) { | ||
app.config.globalProperties.$store = this; | ||
var useDevtools = this._devtools !== undefined | ||
? this._devtools | ||
: true ; | ||
if (useDevtools) { | ||
addDevtools(app, this); | ||
} | ||
}; | ||
prototypeAccessors$1.state.get = function () { | ||
prototypeAccessors.state.get = function () { | ||
return this._state.data | ||
}; | ||
prototypeAccessors$1.state.set = function (v) { | ||
prototypeAccessors.state.set = function (v) { | ||
{ | ||
@@ -432,3 +967,3 @@ assert(false, "use store.replaceState() to explicit replace store state."); | ||
Store.prototype.commit = function commit (_type, _payload, _options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -457,6 +992,5 @@ // check object-style commit | ||
.slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe | ||
.forEach(function (sub) { return sub(mutation, this$1.state); }); | ||
.forEach(function (sub) { return sub(mutation, this$1$1.state); }); | ||
if ( | ||
options && options.silent | ||
@@ -472,3 +1006,3 @@ ) { | ||
Store.prototype.dispatch = function dispatch (_type, _payload) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -493,3 +1027,3 @@ // check object-style dispatch | ||
.filter(function (sub) { return sub.before; }) | ||
.forEach(function (sub) { return sub.before(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.before(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -509,5 +1043,5 @@ { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.after; }) | ||
.forEach(function (sub) { return sub.after(action, this$1.state); }); | ||
.forEach(function (sub) { return sub.after(action, this$1$1.state); }); | ||
} catch (e) { | ||
@@ -522,5 +1056,5 @@ { | ||
try { | ||
this$1._actionSubscribers | ||
this$1$1._actionSubscribers | ||
.filter(function (sub) { return sub.error; }) | ||
.forEach(function (sub) { return sub.error(action, this$1.state, error); }); | ||
.forEach(function (sub) { return sub.error(action, this$1$1.state, error); }); | ||
} catch (e) { | ||
@@ -547,3 +1081,3 @@ { | ||
Store.prototype.watch = function watch$1 (getter, cb, options) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -553,10 +1087,10 @@ { | ||
} | ||
return vue.watch(function () { return getter(this$1.state, this$1.getters); }, cb, Object.assign({}, options)) | ||
return vue.watch(function () { return getter(this$1$1.state, this$1$1.getters); }, cb, Object.assign({}, options)) | ||
}; | ||
Store.prototype.replaceState = function replaceState (state) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
this._withCommit(function () { | ||
this$1._state.data = state; | ||
this$1$1._state.data = state; | ||
}); | ||
@@ -582,3 +1116,3 @@ }; | ||
Store.prototype.unregisterModule = function unregisterModule (path) { | ||
var this$1 = this; | ||
var this$1$1 = this; | ||
@@ -593,3 +1127,3 @@ if (typeof path === 'string') { path = [path]; } | ||
this._withCommit(function () { | ||
var parentState = getNestedState(this$1.state, path.slice(0, -1)); | ||
var parentState = getNestedState(this$1$1.state, path.slice(0, -1)); | ||
delete parentState[path[path.length - 1]]; | ||
@@ -622,283 +1156,5 @@ }); | ||
Object.defineProperties( Store.prototype, prototypeAccessors$1 ); | ||
Object.defineProperties( Store.prototype, prototypeAccessors ); | ||
function genericSubscribe (fn, subs, options) { | ||
if (subs.indexOf(fn) < 0) { | ||
options && options.prepend | ||
? subs.unshift(fn) | ||
: subs.push(fn); | ||
} | ||
return function () { | ||
var i = subs.indexOf(fn); | ||
if (i > -1) { | ||
subs.splice(i, 1); | ||
} | ||
} | ||
} | ||
function resetStore (store, hot) { | ||
store._actions = Object.create(null); | ||
store._mutations = Object.create(null); | ||
store._wrappedGetters = Object.create(null); | ||
store._modulesNamespaceMap = Object.create(null); | ||
var state = store.state; | ||
// init all modules | ||
installModule(store, state, [], store._modules.root, true); | ||
// reset state | ||
resetStoreState(store, state, hot); | ||
} | ||
function resetStoreState (store, state, hot) { | ||
var oldState = store._state; | ||
// bind store public getters | ||
store.getters = {}; | ||
// reset local getters cache | ||
store._makeLocalGettersCache = Object.create(null); | ||
var wrappedGetters = store._wrappedGetters; | ||
var computedObj = {}; | ||
forEachValue(wrappedGetters, function (fn, key) { | ||
// use computed to leverage its lazy-caching mechanism | ||
// direct inline function use will lead to closure preserving oldState. | ||
// using partial to return function with only arguments preserved in closure environment. | ||
computedObj[key] = partial(fn, store); | ||
Object.defineProperty(store.getters, key, { | ||
// TODO: use `computed` when it's possible. at the moment we can't due to | ||
// https://github.com/vuejs/vuex/pull/1883 | ||
get: function () { return computedObj[key](); }, | ||
enumerable: true // for local getters | ||
}); | ||
}); | ||
store._state = vue.reactive({ | ||
data: state | ||
}); | ||
// enable strict mode for new state | ||
if (store.strict) { | ||
enableStrictMode(store); | ||
} | ||
if (oldState) { | ||
if (hot) { | ||
// dispatch changes in all subscribed watchers | ||
// to force getter re-evaluation for hot reloading. | ||
store._withCommit(function () { | ||
oldState.data = null; | ||
}); | ||
} | ||
} | ||
} | ||
function installModule (store, rootState, path, module, hot) { | ||
var isRoot = !path.length; | ||
var namespace = store._modules.getNamespace(path); | ||
// register in namespace map | ||
if (module.namespaced) { | ||
if (store._modulesNamespaceMap[namespace] && true) { | ||
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/')))); | ||
} | ||
store._modulesNamespaceMap[namespace] = module; | ||
} | ||
// set state | ||
if (!isRoot && !hot) { | ||
var parentState = getNestedState(rootState, path.slice(0, -1)); | ||
var moduleName = path[path.length - 1]; | ||
store._withCommit(function () { | ||
{ | ||
if (moduleName in parentState) { | ||
console.warn( | ||
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"") | ||
); | ||
} | ||
} | ||
parentState[moduleName] = module.state; | ||
}); | ||
} | ||
var local = module.context = makeLocalContext(store, namespace, path); | ||
module.forEachMutation(function (mutation, key) { | ||
var namespacedType = namespace + key; | ||
registerMutation(store, namespacedType, mutation, local); | ||
}); | ||
module.forEachAction(function (action, key) { | ||
var type = action.root ? key : namespace + key; | ||
var handler = action.handler || action; | ||
registerAction(store, type, handler, local); | ||
}); | ||
module.forEachGetter(function (getter, key) { | ||
var namespacedType = namespace + key; | ||
registerGetter(store, namespacedType, getter, local); | ||
}); | ||
module.forEachChild(function (child, key) { | ||
installModule(store, rootState, path.concat(key), child, hot); | ||
}); | ||
} | ||
/** | ||
* make localized dispatch, commit, getters and state | ||
* if there is no namespace, just use root ones | ||
*/ | ||
function makeLocalContext (store, namespace, path) { | ||
var noNamespace = namespace === ''; | ||
var local = { | ||
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ( !store._actions[type]) { | ||
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
return store.dispatch(type, payload) | ||
}, | ||
commit: noNamespace ? store.commit : function (_type, _payload, _options) { | ||
var args = unifyObjectStyle(_type, _payload, _options); | ||
var payload = args.payload; | ||
var options = args.options; | ||
var type = args.type; | ||
if (!options || !options.root) { | ||
type = namespace + type; | ||
if ( !store._mutations[type]) { | ||
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); | ||
return | ||
} | ||
} | ||
store.commit(type, payload, options); | ||
} | ||
}; | ||
// getters and state object must be gotten lazily | ||
// because they will be changed by state update | ||
Object.defineProperties(local, { | ||
getters: { | ||
get: noNamespace | ||
? function () { return store.getters; } | ||
: function () { return makeLocalGetters(store, namespace); } | ||
}, | ||
state: { | ||
get: function () { return getNestedState(store.state, path); } | ||
} | ||
}); | ||
return local | ||
} | ||
function makeLocalGetters (store, namespace) { | ||
if (!store._makeLocalGettersCache[namespace]) { | ||
var gettersProxy = {}; | ||
var splitPos = namespace.length; | ||
Object.keys(store.getters).forEach(function (type) { | ||
// skip if the target getter is not match this namespace | ||
if (type.slice(0, splitPos) !== namespace) { return } | ||
// extract local getter type | ||
var localType = type.slice(splitPos); | ||
// Add a port to the getters proxy. | ||
// Define as getter property because | ||
// we do not want to evaluate the getters in this time. | ||
Object.defineProperty(gettersProxy, localType, { | ||
get: function () { return store.getters[type]; }, | ||
enumerable: true | ||
}); | ||
}); | ||
store._makeLocalGettersCache[namespace] = gettersProxy; | ||
} | ||
return store._makeLocalGettersCache[namespace] | ||
} | ||
function registerMutation (store, type, handler, local) { | ||
var entry = store._mutations[type] || (store._mutations[type] = []); | ||
entry.push(function wrappedMutationHandler (payload) { | ||
handler.call(store, local.state, payload); | ||
}); | ||
} | ||
function registerAction (store, type, handler, local) { | ||
var entry = store._actions[type] || (store._actions[type] = []); | ||
entry.push(function wrappedActionHandler (payload) { | ||
var res = handler.call(store, { | ||
dispatch: local.dispatch, | ||
commit: local.commit, | ||
getters: local.getters, | ||
state: local.state, | ||
rootGetters: store.getters, | ||
rootState: store.state | ||
}, payload); | ||
if (!isPromise(res)) { | ||
res = Promise.resolve(res); | ||
} | ||
if (store._devtoolHook) { | ||
return res.catch(function (err) { | ||
store._devtoolHook.emit('vuex:error', err); | ||
throw err | ||
}) | ||
} else { | ||
return res | ||
} | ||
}); | ||
} | ||
function registerGetter (store, type, rawGetter, local) { | ||
if (store._wrappedGetters[type]) { | ||
{ | ||
console.error(("[vuex] duplicate getter key: " + type)); | ||
} | ||
return | ||
} | ||
store._wrappedGetters[type] = function wrappedGetter (store) { | ||
return rawGetter( | ||
local.state, // local state | ||
local.getters, // local getters | ||
store.state, // root state | ||
store.getters // root getters | ||
) | ||
}; | ||
} | ||
function enableStrictMode (store) { | ||
vue.watch(function () { return store._state.data; }, function () { | ||
{ | ||
assert(store._committing, "do not mutate vuex store state outside mutation handlers."); | ||
} | ||
}, { deep: true, flush: 'sync' }); | ||
} | ||
function getNestedState (state, path) { | ||
return path.reduce(function (state, key) { return state[key]; }, state) | ||
} | ||
function unifyObjectStyle (type, payload, options) { | ||
if (isObject(type) && type.type) { | ||
options = payload; | ||
payload = type; | ||
type = type.type; | ||
} | ||
{ | ||
assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + ".")); | ||
} | ||
return { type: type, payload: payload, options: options } | ||
} | ||
/** | ||
* Reduce the code which written in Vue.js for getting the state. | ||
@@ -911,3 +1167,3 @@ * @param {String} [namespace] - Module's namespace | ||
var res = {}; | ||
if ( !isValidMap(states)) { | ||
if (!isValidMap(states)) { | ||
console.error('[vuex] mapState: mapper parameter must be either an Array or an Object'); | ||
@@ -948,3 +1204,3 @@ } | ||
var res = {}; | ||
if ( !isValidMap(mutations)) { | ||
if (!isValidMap(mutations)) { | ||
console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object'); | ||
@@ -985,3 +1241,3 @@ } | ||
var res = {}; | ||
if ( !isValidMap(getters)) { | ||
if (!isValidMap(getters)) { | ||
console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object'); | ||
@@ -999,3 +1255,3 @@ } | ||
} | ||
if ( !(val in this.$store.getters)) { | ||
if (!(val in this.$store.getters)) { | ||
console.error(("[vuex] unknown getter: " + val)); | ||
@@ -1020,3 +1276,3 @@ return | ||
var res = {}; | ||
if ( !isValidMap(actions)) { | ||
if (!isValidMap(actions)) { | ||
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object'); | ||
@@ -1112,3 +1368,3 @@ } | ||
var module = store._modulesNamespaceMap[namespace]; | ||
if ( !module) { | ||
if (!module) { | ||
console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); | ||
@@ -1211,3 +1467,3 @@ } | ||
var index_cjs = { | ||
version: '4.0.0', | ||
version: '4.0.1', | ||
Store: Store, | ||
@@ -1214,0 +1470,0 @@ storeKey: storeKey, |
/*! | ||
* vuex v4.0.0 | ||
* vuex v4.0.1 | ||
* (c) 2021 Evan You | ||
* @license MIT | ||
*/ | ||
var Vuex=function(t){"use strict";var e="store";var n=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;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 o(t,e){Object.keys(t).forEach((function(n){return e(t[n],n)}))}function i(t){return null!==t&&"object"==typeof t}var a=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)||{}},c={namespaced:{configurable:!0}};c.namespaced.get=function(){return!!this._rawModule.namespaced},a.prototype.addChild=function(t,e){this._children[t]=e},a.prototype.removeChild=function(t){delete this._children[t]},a.prototype.getChild=function(t){return this._children[t]},a.prototype.hasChild=function(t){return t in this._children},a.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)},a.prototype.forEachChild=function(t){o(this._children,t)},a.prototype.forEachGetter=function(t){this._rawModule.getters&&o(this._rawModule.getters,t)},a.prototype.forEachAction=function(t){this._rawModule.actions&&o(this._rawModule.actions,t)},a.prototype.forEachMutation=function(t){this._rawModule.mutations&&o(this._rawModule.mutations,t)},Object.defineProperties(a.prototype,c);var s=function(t){this.register([],t,!1)};function u(t,e,n){if(e.update(n),n.modules)for(var r in n.modules){if(!e.getChild(r))return;u(t.concat(r),e.getChild(r),n.modules[r])}}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){u([],this.root,t)},s.prototype.register=function(t,e,n){var r=this;void 0===n&&(n=!0);var i=new a(e,n);0===t.length?this.root=i:this.get(t.slice(0,-1)).addChild(t[t.length-1],i);e.modules&&o(e.modules,(function(e,o){r.register(t.concat(o),e,n)}))},s.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1],r=e.getChild(n);r&&r.runtime&&e.removeChild(n)},s.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return!!e&&e.hasChild(n)};var f=function(t){var e=this;void 0===t&&(t={});var r=t.plugins;void 0===r&&(r=[]);var o=t.strict;void 0===o&&(o=!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(t),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._makeLocalGettersCache=Object.create(null);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 u=this._modules.root.state;m(this,u,[],this._modules.root),d(this,u),r.forEach((function(t){return t(e)})),(void 0===t.devtools||t.devtools)&&function(t){n&&(t._devtoolHook=n,n.emit("vuex:init",t),n.on("vuex:travel-to-state",(function(e){t.replaceState(e)})),t.subscribe((function(t,e){n.emit("vuex:mutation",t,e)}),{prepend:!0}),t.subscribeAction((function(t,e){n.emit("vuex:action",t,e)}),{prepend:!0}))}(this)},l={state:{configurable:!0}};function h(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 p(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;m(t,n,[],t._modules.root,!0),d(t,n,e)}function d(e,n,r){var i=e._state;e.getters={},e._makeLocalGettersCache=Object.create(null);var a=e._wrappedGetters,c={};o(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),i&&r&&e._withCommit((function(){i.data=null}))}function m(t,e,n,r,o){var i=!n.length,a=t._modules.getNamespace(n);if(r.namespaced&&(t._modulesNamespaceMap[a],t._modulesNamespaceMap[a]=r),!i&&!o){var c=v(e,n.slice(0,-1)),s=n[n.length-1];t._withCommit((function(){c[s]=r.state}))}var u=r.context=function(t,e,n){var r=""===e,o={dispatch:r?t.dispatch:function(n,r,o){var i=g(n,r,o),a=i.payload,c=i.options,s=i.type;return c&&c.root||(s=e+s),t.dispatch(s,a)},commit:r?t.commit:function(n,r,o){var i=g(n,r,o),a=i.payload,c=i.options,s=i.type;c&&c.root||(s=e+s),t.commit(s,a,c)}};return Object.defineProperties(o,{getters:{get:r?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},r=e.length;Object.keys(t.getters).forEach((function(o){if(o.slice(0,r)===e){var i=o.slice(r);Object.defineProperty(n,i,{get:function(){return t.getters[o]},enumerable:!0})}})),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}(t,e)}},state:{get:function(){return v(t.state,n)}}}),o}(t,a,n);r.forEachMutation((function(e,n){!function(t,e,n,r){(t._mutations[e]||(t._mutations[e]=[])).push((function(e){n.call(t,r.state,e)}))}(t,a+n,e,u)})),r.forEachAction((function(e,n){var r=e.root?n:a+n,o=e.handler||e;!function(t,e,n,r){(t._actions[e]||(t._actions[e]=[])).push((function(e){var o,i=n.call(t,{dispatch:r.dispatch,commit:r.commit,getters:r.getters,state:r.state,rootGetters:t.getters,rootState:t.state},e);return(o=i)&&"function"==typeof o.then||(i=Promise.resolve(i)),t._devtoolHook?i.catch((function(e){throw t._devtoolHook.emit("vuex:error",e),e})):i}))}(t,r,o,u)})),r.forEachGetter((function(e,n){!function(t,e,n,r){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return n(r.state,r.getters,t.state,t.getters)}}(t,a+n,e,u)})),r.forEachChild((function(r,i){m(t,e,n.concat(i),r,o)}))}function v(t,e){return e.reduce((function(t,e){return t[e]}),t)}function g(t,e,n){return i(t)&&t.type&&(n=e,e=t,t=t.type),{type:t,payload:e,options:n}}f.prototype.install=function(t,n){t.provide(n||e,this),t.config.globalProperties.$store=this},l.state.get=function(){return this._state.data},l.state.set=function(t){},f.prototype.commit=function(t,e,n){var r=this,o=g(t,e,n),i=o.type,a=o.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,r.state)})))},f.prototype.dispatch=function(t,e){var n=this,r=g(t,e),o=r.type,i=r.payload,a={type:o,payload:i},c=this._actions[o];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)}))}))}},f.prototype.subscribe=function(t,e){return h(t,this._subscribers,e)},f.prototype.subscribeAction=function(t,e){return h("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},f.prototype.watch=function(e,n,r){var o=this;return t.watch((function(){return e(o.state,o.getters)}),n,Object.assign({},r))},f.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._state.data=t}))},f.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),m(this,this.state,t,this._modules.get(t),n.preserveState),d(this,this.state)},f.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit((function(){delete v(e.state,t.slice(0,-1))[t[t.length-1]]})),p(this)},f.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},f.prototype.hotUpdate=function(t){this._modules.update(t),p(this,!0)},f.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(f.prototype,l);var y=O((function(t,e){var n={};return M(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var r=C(this.$store,"mapState",t);if(!r)return;e=r.context.state,n=r.context.getters}return"function"==typeof o?o.call(this,e,n):e[o]},n[r].vuex=!0})),n})),_=O((function(t,e){var n={};return M(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.commit;if(t){var i=C(this.$store,"mapMutations",t);if(!i)return;r=i.context.commit}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n})),b=O((function(t,e){var n={};return M(e).forEach((function(e){var r=e.key,o=e.val;o=t+o,n[r]=function(){if(!t||C(this.$store,"mapGetters",t))return this.$store.getters[o]},n[r].vuex=!0})),n})),w=O((function(t,e){var n={};return M(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.dispatch;if(t){var i=C(this.$store,"mapActions",t);if(!i)return;r=i.context.dispatch}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n}));function M(t){return function(t){return Array.isArray(t)||i(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 O(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function C(t,e,n){return t._modulesNamespaceMap[n]}function E(t,e,n){var r=n?t.groupCollapsed:t.group;try{r.call(t,e)}catch(n){t.log(e)}}function j(t){try{t.groupEnd()}catch(e){t.log("—— log end ——")}}function A(){var t=new Date;return" @ "+k(t.getHours(),2)+":"+k(t.getMinutes(),2)+":"+k(t.getSeconds(),2)+"."+k(t.getMilliseconds(),3)}function k(t,e){return n="0",r=e-t.toString().length,new Array(r+1).join(n)+t;var n,r}return{version:"4.0.0",Store:f,storeKey:e,createStore:function(t){return new f(t)},useStore:function(n){return void 0===n&&(n=null),t.inject(null!==n?n:e)},mapState:y,mapMutations:_,mapGetters:b,mapActions:w,createNamespacedHelpers:function(t){return{mapState:y.bind(null,t),mapGetters:b.bind(null,t),mapMutations:_.bind(null,t),mapActions:w.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 f=t.logger;return void 0===f&&(f=console),function(t){var l=r(t.state);void 0!==f&&(s&&t.subscribe((function(t,a){var c=r(a);if(n(t,l,c)){var s=A(),u=i(t),h="mutation "+t.type+s;E(f,h,e),f.log("%c prev state","color: #9E9E9E; font-weight: bold",o(l)),f.log("%c mutation","color: #03A9F4; font-weight: bold",u),f.log("%c next state","color: #4CAF50; font-weight: bold",o(c)),j(f)}l=c})),u&&t.subscribeAction((function(t,n){if(a(t,n)){var r=A(),o=c(t),i="action "+t.type+r;E(f,i,e),f.log("%c action","color: #03A9F4; font-weight: bold",o),j(f)}})))}}}}(Vue); | ||
var 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 s(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 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),u(t,n,e)}function u(e,n,o){var r=e._state;e.getters={},e._makeLocalGettersCache=Object.create(null);var a=e._wrappedGetters,s={};i(a,(function(t,n){s[n]=function(t,e){return function(){return t(e)}}(t,e),Object.defineProperty(e.getters,n,{get:function(){return s[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 s=p(e,n.slice(0,-1)),c=n[n.length-1];t._withCommit((function(){s[c]=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,s=i.options,c=i.type;return s&&s.root||(c=e+c),t.dispatch(c,a)},commit:o?t.commit:function(n,o,r){var i=d(n,o,r),a=i.payload,s=i.options,c=i.type;s&&s.root||(c=e+c),t.commit(c,a,s)}};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",m="vuex:actions",v="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:m,label:"Vuex Actions",color:_}),n.addInspector({id:v,label:"Vuex",icon:"storage",treeFilterPlaceholder:"Filter stores..."}),n.on.getInspectorTree((function(n){if(n.app===t&&n.inspectorId===v)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===v){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]}}))};o.length&&(r.getters=o.map((function(t){return{key:t.endsWith("/")?w(t):t,editable:!1,value:e[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)),e._makeLocalGettersCache,o)}var r,i,a})),n.on.editInspectorState((function(n){if(n.app===t&&n.inspectorId===v){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(v),n.sendInspectorState(v),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:m,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:m,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+"/")}))}var j=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)||{}},C={namespaced:{configurable:!0}};C.namespaced.get=function(){return!!this._rawModule.namespaced},j.prototype.addChild=function(t,e){this._children[t]=e},j.prototype.removeChild=function(t){delete this._children[t]},j.prototype.getChild=function(t){return this._children[t]},j.prototype.hasChild=function(t){return t in this._children},j.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)},j.prototype.forEachChild=function(t){i(this._children,t)},j.prototype.forEachGetter=function(t){this._rawModule.getters&&i(this._rawModule.getters,t)},j.prototype.forEachAction=function(t){this._rawModule.actions&&i(this._rawModule.actions,t)},j.prototype.forEachMutation=function(t){this._rawModule.mutations&&i(this._rawModule.mutations,t)},Object.defineProperties(j.prototype,C);var M=function(t){this.register([],t,!1)};function k(t,e,n){if(e.update(n),n.modules)for(var o in n.modules){if(!e.getChild(o))return;k(t.concat(o),e.getChild(o),n.modules[o])}}M.prototype.get=function(t){return t.reduce((function(t,e){return t.getChild(e)}),this.root)},M.prototype.getNamespace=function(t){var e=this.root;return t.reduce((function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")}),"")},M.prototype.update=function(t){k([],this.root,t)},M.prototype.register=function(t,e,n){var o=this;void 0===n&&(n=!0);var r=new j(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)}))},M.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)},M.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return!!e&&e.hasChild(n)};var x=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 M(t),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._makeLocalGettersCache=Object.create(null),this._devtools=r;var i=this,a=this.dispatch,s=this.commit;this.dispatch=function(t,e){return a.call(i,t,e)},this.commit=function(t,e,n){return s.call(i,t,e,n)},this.strict=o;var c=this._modules.root.state;l(this,c,[],this._modules.root),u(this,c),n.forEach((function(t){return t(e)}))},S={state:{configurable:!0}};x.prototype.install=function(t,n){t.provide(n||e,this),t.config.globalProperties.$store=this,void 0!==this._devtools&&this._devtools&&y(t,this)},S.state.get=function(){return this._state.data},S.state.set=function(t){},x.prototype.commit=function(t,e,n){var o=this,r=d(t,e,n),i=r.type,a=r.payload,s={type:i,payload:a},c=this._mutations[i];c&&(this._withCommit((function(){c.forEach((function(t){t(a)}))})),this._subscribers.slice().forEach((function(t){return t(s,o.state)})))},x.prototype.dispatch=function(t,e){var n=this,o=d(t,e),r=o.type,i=o.payload,a={type:r,payload:i},s=this._actions[r];if(s){try{this._actionSubscribers.slice().filter((function(t){return t.before})).forEach((function(t){return t.before(a,n.state)}))}catch(t){}var c=s.length>1?Promise.all(s.map((function(t){return t(i)}))):s[0](i);return new Promise((function(t,e){c.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)}))}))}},x.prototype.subscribe=function(t,e){return s(t,this._subscribers,e)},x.prototype.subscribeAction=function(t,e){return s("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},x.prototype.watch=function(e,n,o){var r=this;return t.watch((function(){return e(r.state,r.getters)}),n,Object.assign({},o))},x.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._state.data=t}))},x.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)},x.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]]})),c(this)},x.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},x.prototype.hotUpdate=function(t){this._modules.update(t),c(this,!0)},x.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(x.prototype,S);var A=T((function(t,e){var n={};return N(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=P(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})),G=T((function(t,e){var n={};return N(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=P(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})),I=T((function(t,e){var n={};return N(e).forEach((function(e){var o=e.key,r=e.val;r=t+r,n[o]=function(){if(!t||P(this.$store,"mapGetters",t))return this.$store.getters[r]},n[o].vuex=!0})),n})),L=T((function(t,e){var n={};return N(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=P(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 N(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 T(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function P(t,e,n){return t._modulesNamespaceMap[n]}function V(t,e,n){var o=n?t.groupCollapsed:t.group;try{o.call(t,e)}catch(n){t.log(e)}}function $(t){try{t.groupEnd()}catch(e){t.log("—— log end ——")}}function D(){var t=new Date;return" @ "+F(t.getHours(),2)+":"+F(t.getMinutes(),2)+":"+F(t.getSeconds(),2)+"."+F(t.getMilliseconds(),3)}function F(t,e){return n="0",o=e-t.toString().length,new Array(o+1).join(n)+t;var n,o}return{version:"4.0.1",Store:x,storeKey:e,createStore:function(t){return new x(t)},useStore:function(n){return void 0===n&&(n=null),t.inject(null!==n?n:e)},mapState:A,mapMutations:G,mapGetters:I,mapActions:L,createNamespacedHelpers:function(t){return{mapState:A.bind(null,t),mapGetters:I.bind(null,t),mapMutations:G.bind(null,t),mapActions:L.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 s=t.actionTransformer;void 0===s&&(s=function(t){return t});var c=t.logMutations;void 0===c&&(c=!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&&(c&&t.subscribe((function(t,a){var s=r(a);if(n(t,f,s)){var c=D(),u=i(t),p="mutation "+t.type+c;V(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(s)),$(l)}f=s})),u&&t.subscribeAction((function(t,n){if(a(t,n)){var o=D(),r=s(t),i="action "+t.type+o;V(l,i,e),l.log("%c action","color: #03A9F4; font-weight: bold",r),$(l)}})))}}}}(Vue); |
{ | ||
"name": "vuex", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "state management for Vue.js", | ||
@@ -57,15 +57,18 @@ "main": "dist/vuex.cjs.js", | ||
}, | ||
"dependencies": { | ||
"@vue/devtools-api": "^6.0.0-beta.11" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/core": "^7.14.3", | ||
"@babel/preset-env": "^7.14.2", | ||
"@rollup/plugin-buble": "^0.21.3", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.1.1", | ||
"@rollup/plugin-replace": "^2.3.2", | ||
"@types/node": "^14.14.22", | ||
"@vue/compiler-sfc": "^3.0.5", | ||
"@rollup/plugin-commonjs": "^19.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@rollup/plugin-replace": "^2.4.2", | ||
"@types/node": "^15.6.0", | ||
"@vue/compiler-sfc": "^3.0.11", | ||
"babel-jest": "^26.6.3", | ||
"babel-loader": "^8.2.2", | ||
"brotli": "^1.3.2", | ||
"chalk": "^4.0.0", | ||
"chalk": "^4.1.1", | ||
"conventional-changelog-cli": "^2.1.1", | ||
@@ -75,20 +78,20 @@ "cross-env": "^7.0.3", | ||
"enquirer": "^2.3.5", | ||
"eslint": "^6.8.0", | ||
"eslint": "^7.27.0", | ||
"eslint-plugin-vue-libs": "^4.0.0", | ||
"execa": "^5.0.0", | ||
"express": "^4.17.1", | ||
"fs-extra": "^9.1.0", | ||
"fs-extra": "^10.0.0", | ||
"jest": "^26.6.3", | ||
"puppeteer": "^5.5.0", | ||
"puppeteer": "^9.1.1", | ||
"regenerator-runtime": "^0.13.5", | ||
"rollup": "^2.38.4", | ||
"rollup": "^2.49.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"semver": "^7.3.4", | ||
"start-server-and-test": "^1.12.0", | ||
"todomvc-app-css": "^2.3.0", | ||
"typescript": "^4.1.3", | ||
"semver": "^7.3.5", | ||
"start-server-and-test": "^1.12.3", | ||
"todomvc-app-css": "^2.4.1", | ||
"typescript": "^4.2.4", | ||
"vitepress": "^0.11.5", | ||
"vue": "^3.0.5", | ||
"vue-loader": "^16.1.2", | ||
"vue-style-loader": "^4.1.2", | ||
"vue": "^3.0.11", | ||
"vue-loader": "^16.2.0", | ||
"vue-style-loader": "^4.1.3", | ||
"webpack": "^4.43.0", | ||
@@ -95,0 +98,0 @@ "webpack-dev-middleware": "^3.7.2", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260403
6341
2
60
+ Added@vue/compiler-core@3.5.12(transitive)
+ Added@vue/compiler-dom@3.5.12(transitive)
+ Added@vue/compiler-sfc@3.5.12(transitive)
+ Added@vue/compiler-ssr@3.5.12(transitive)
+ Added@vue/devtools-api@6.6.4(transitive)
+ Added@vue/reactivity@3.5.12(transitive)
+ Added@vue/runtime-core@3.5.12(transitive)
+ Added@vue/runtime-dom@3.5.12(transitive)
+ Added@vue/server-renderer@3.5.12(transitive)
+ Added@vue/shared@3.5.12(transitive)
+ Addedvue@3.5.12(transitive)
- Removed@vue/compiler-core@3.5.13(transitive)
- Removed@vue/compiler-dom@3.5.13(transitive)
- Removed@vue/compiler-sfc@3.5.13(transitive)
- Removed@vue/compiler-ssr@3.5.13(transitive)
- Removed@vue/reactivity@3.5.13(transitive)
- Removed@vue/runtime-core@3.5.13(transitive)
- Removed@vue/runtime-dom@3.5.13(transitive)
- Removed@vue/server-renderer@3.5.13(transitive)
- Removed@vue/shared@3.5.13(transitive)
- Removedvue@3.5.13(transitive)