You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
138 KiB

1 month ago
  1. {"ast":null,"code":"/*!\n * vuex v4.1.0\n * (c) 2022 Evan You\n * @license MIT\n */\nimport { inject, effectScope, reactive, watch, computed } from 'vue';\nimport { setupDevtoolsPlugin } from '@vue/devtools-api';\nvar storeKey = 'store';\nfunction useStore(key) {\n if (key === void 0) key = null;\n return inject(key !== null ? key : storeKey);\n}\n\n/**\n * Get the first item that pass the test\n * by second argument function\n *\n * @param {Array} list\n * @param {Function} f\n * @return {*}\n */\nfunction find(list, f) {\n return list.filter(f)[0];\n}\n\n/**\n * Deep copy the given object considering circular structure.\n * This function caches all nested objects and its copies.\n * If it detects circular structure, use cached copy to avoid infinite loop.\n *\n * @param {*} obj\n * @param {Array<Object>} cache\n * @return {*}\n */\nfunction deepCopy(obj, cache) {\n if (cache === void 0) cache = [];\n\n // just return if obj is immutable value\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n // if obj is hit, it is in circular structure\n var hit = find(cache, function (c) {\n return c.original === obj;\n });\n if (hit) {\n return hit.copy;\n }\n var copy = Array.isArray(obj) ? [] : {};\n // put the copy into cache at first\n // because we want to refer it in recursive deepCopy\n cache.push({\n original: obj,\n copy: copy\n });\n Object.keys(obj).forEach(function (key) {\n copy[key] = deepCopy(obj[key], cache);\n });\n return copy;\n}\n\n/**\n * forEach for object\n */\nfunction forEachValue(obj, fn) {\n Object.keys(obj).forEach(function (key) {\n return fn(obj[key], key);\n });\n}\nfunction isObject(obj) {\n return obj !== null && typeof obj === 'object';\n}\nfunction isPromise(val) {\n return val && typeof val.then === 'function';\n}\nfunction assert(condition, msg) {\n if (!condition) {\n throw new Error(\"[vuex] \" + msg);\n }\n}\nfunction partial(fn, arg) {\n return function () {\n return fn(arg);\n };\n}\nfunction genericSubscribe(fn, subs, options) {\n if (subs.indexOf(fn) < 0) {\n options && options.prepend ? subs.unshift(fn) : subs.push(fn);\n }\n return function () {\n var i = subs.indexOf(fn);\n if (i > -1) {\n subs.splice(i, 1);\n }\n };\n}\nfunction resetStore(store, hot) {\n store._actions = Object.create(null);\n store._mutations = Object.create(null);\n store._wrappedGetters = Object.create(null);\n store._modulesNamespaceMap = Object.create(null);\n var state = store.state;\n // init all modules\n installModule(store, state, [], store._modules.root, true);\n // reset state\n resetStoreState(store, state, hot);\n}\nfunction resetStoreState(store, state, hot) {\n var oldState = store._state;\n var oldScope = store._scope;\n\n // bind store public getters\n store.getters = {};\n // reset local getters cache\n store._makeLocalGettersCache = Object.create(null);\n var wrappedGetters = store._wrappedGetters;\n var computedObj = {};\n var computedCache = {};\n\n // create a new effect scope and create computed object inside it to avoid\n // getters (computed) getting destroyed on component unmount.\n var scope = effectScope(true);\n scope.run(function () {\n forEachValue(wrappedGetters, function (fn, key) {\n // use computed to leverage its lazy-caching mechanism\n // direct inline function use will lead to closure preserving oldState.\n // using partial to return function with only arguments preserved in closure environment.\n computedObj[key] = partial(fn, store);\n computedCache[key] = computed(function () {\n return computedObj[key]();\n });\n Object.defineProperty(store.getters, key, {\n get: function () {\n return computedCache[key].value;\n },\n enumerable: true // for local getters\n });\n });\n });\n store._state = reactive({\n data: state\n });\n\n // register the newly created effect scope to the store so that we can\n // dispose the effects when this method runs again in the future.\n stor