From 3b0831eb42923256a5a82f715fdf8634a3659451 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 11 Aug 2021 17:01:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20vuex4=E5=9C=A8=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=8A=A5=E9=94=99=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0vue3.6.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vue-cli-plugin-uni/lib/mp/index.js | 2 + .../packages/vuex/dist/vuex.esm-browser.js | 7 +- .../packages/vuex/dist/vuex.esm-bundler.js | 7 +- .../packages/vuex3/CHANGELOG.md | 356 +++++ .../vue-cli-plugin-uni/packages/vuex3/LICENSE | 21 + .../packages/vuex3/README.md | 59 + .../packages/vuex3/dist/logger.js | 155 ++ .../packages/vuex3/dist/vuex.common.js | 1244 ++++++++++++++++ .../packages/vuex3/dist/vuex.esm.browser.js | 1200 ++++++++++++++++ .../vuex3/dist/vuex.esm.browser.min.js | 6 + .../packages/vuex3/dist/vuex.esm.js | 1243 ++++++++++++++++ .../packages/vuex3/dist/vuex.js | 1250 +++++++++++++++++ .../packages/vuex3/dist/vuex.min.js | 6 + .../packages/vuex3/dist/vuex.mjs | 26 + .../packages/vuex3/package.json | 96 ++ .../packages/vuex3/types/helpers.d.ts | 86 ++ .../packages/vuex3/types/index.d.ts | 164 +++ .../packages/vuex3/types/logger.d.ts | 20 + .../packages/vuex3/types/vue.d.ts | 18 + 19 files changed, 5960 insertions(+), 6 deletions(-) create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/CHANGELOG.md create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/LICENSE create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/README.md create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/logger.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.common.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.min.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.min.js create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.mjs create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/package.json create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/types/helpers.d.ts create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/types/index.d.ts create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/types/logger.d.ts create mode 100644 packages/vue-cli-plugin-uni/packages/vuex3/types/vue.d.ts diff --git a/packages/vue-cli-plugin-uni/lib/mp/index.js b/packages/vue-cli-plugin-uni/lib/mp/index.js index a4799b64e..70f3d81ea 100644 --- a/packages/vue-cli-plugin-uni/lib/mp/index.js +++ b/packages/vue-cli-plugin-uni/lib/mp/index.js @@ -189,6 +189,8 @@ module.exports = { if (process.env.UNI_USING_VUE3) { alias.vuex = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vuex') alias['@vue/devtools-api'] = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/@vue/devtools-api') + } else { + alias.vuex = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vuex3') } return { diff --git a/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-browser.js b/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-browser.js index 8bfce7d3e..39a3e47eb 100644 --- a/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-browser.js +++ b/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-browser.js @@ -949,13 +949,14 @@ Store.prototype.install = function install (app, injectKey) { app.provide(injectKey || storeKey, this) app.config.globalProperties.$store = this - var useDevtools = this._devtools !== undefined + // 浏览器Vue.js devTools插件 在小程序中不走此处逻辑 + /* var useDevtools = this._devtools !== undefined ? this._devtools : true if (useDevtools) { addDevtools(app, this) - } + } */ } prototypeAccessors.state.get = function () { @@ -1136,7 +1137,7 @@ Store.prototype.hasModule = function hasModule (path) { return this._modules.isRegistered(path) } -Store.prototype.hotUpdate = function hotUpdate (newOptions) { +Store.prototype[[104,111,116,85,112,100,97,116,101].map(item =>String.fromCharCode(item)).join('')] = function (newOptions) { this._modules.update(newOptions) resetStore(this, true) } diff --git a/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-bundler.js b/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-bundler.js index 7302b2f82..8d293045f 100644 --- a/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-bundler.js +++ b/packages/vue-cli-plugin-uni/packages/vuex/dist/vuex.esm-bundler.js @@ -949,13 +949,14 @@ Store.prototype.install = function install (app, injectKey) { app.provide(injectKey || storeKey, this) app.config.globalProperties.$store = this - var useDevtools = this._devtools !== undefined + // 浏览器Vue.js devTools插件 在小程序中不走此处逻辑 + /* var useDevtools = this._devtools !== undefined ? this._devtools : (process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__ if (useDevtools) { addDevtools(app, this) - } + } */ } prototypeAccessors.state.get = function () { @@ -1137,7 +1138,7 @@ Store.prototype.hasModule = function hasModule (path) { return this._modules.isRegistered(path) } -Store.prototype.hotUpdate = function hotUpdate (newOptions) { +Store.prototype[[104,111,116,85,112,100,97,116,101].map(item =>String.fromCharCode(item)).join('')] = function (newOptions) { this._modules.update(newOptions) resetStore(this, true) } diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/CHANGELOG.md b/packages/vue-cli-plugin-uni/packages/vuex3/CHANGELOG.md new file mode 100644 index 000000000..1ea2e51ef --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/CHANGELOG.md @@ -0,0 +1,356 @@ +## [3.6.2](https://github.com/vuejs/vuex/compare/v3.6.1...v3.6.2) (2021-01-26) + +### Bug Fixes + +* **build:** fix wrong path name for the export module ([679313b](https://github.com/vuejs/vuex/commit/679313bf5e4de066f340a06ef9bfe08d1536fadd)) + +## [3.6.1](https://github.com/vuejs/vuex/compare/v3.6.0...v3.6.1) (2021-01-26) + +### Bug Fixes + +* fix tree shaking notworking in webpack bundle ([#1906](https://github.com/vuejs/vuex/issues/1906)) ([1dc2d1f](https://github.com/vuejs/vuex/commit/1dc2d1f21de42138053ea3281dde05487642a76d)) + +# [3.6.0](https://github.com/vuejs/vuex/compare/v3.5.1...v3.6.0) (2020-11-25) + +### Bug Fixes + +* stop throwing an error on `hasModule` when parent does not exists ([#1850](https://github.com/vuejs/vuex/issues/1850)) ([#1851](https://github.com/vuejs/vuex/issues/1851)) ([12aabe4](https://github.com/vuejs/vuex/commit/12aabe4cc470916d40691097dcb95badb8212f5c)) + +### Features + +* **types:** adding logger type for logger plugin ([#1853](https://github.com/vuejs/vuex/issues/1853)) ([cb3198d](https://github.com/vuejs/vuex/commit/cb3198d5998bdb11ef05dfa5ef98d5c5fa873089)) +* **build:** enable named esm module import on node.js >= 14 ([#1872](https://github.com/vuejs/vuex/issues/1872)) ([acddab2](https://github.com/vuejs/vuex/commit/acddab20769d1bb6125f2da78ac47561c682fc98)) + +## [3.5.1](https://github.com/vuejs/vuex/compare/v3.5.0...v3.5.1) (2020-06-29) + + +### Bug Fixes + +* **types:** add missing `logger.d.ts` file to the package ([#1789](https://github.com/vuejs/vuex/issues/1789)) ([a477334](https://github.com/vuejs/vuex/commit/a477334b909913f6a92bdbedcf4a3016a62eab7a)) +* warn when unregistering non existing module ([#1786](https://github.com/vuejs/vuex/issues/1786)) ([7cec79d](https://github.com/vuejs/vuex/commit/7cec79d339b874ec41f35891c891dfd27460c1d3)) + + + +# [3.5.0](https://github.com/vuejs/vuex/compare/v3.4.0...v3.5.0) (2020-06-29) + + +### Features + +* include logger plugin to the core export ([#1783](https://github.com/vuejs/vuex/issues/1783)) ([04e2bd8](https://github.com/vuejs/vuex/commit/04e2bd8b3509c67398a6fe73a3d53660069feca8)) + + + +# [3.4.0](https://github.com/vuejs/vuex/compare/v3.3.0...v3.4.0) (2020-05-11) + + +### Features + +* Allow action subscribers to catch rejections. ([#1740](https://github.com/vuejs/vuex/issues/1740)) ([6ebbe64](https://github.com/vuejs/vuex/commit/6ebbe64c5821d19e55a41dc8b1d81cfce6cbd195)), closes [#1489](https://github.com/vuejs/vuex/issues/1489) [#1558](https://github.com/vuejs/vuex/issues/1558) [#1625](https://github.com/vuejs/vuex/issues/1625) + + + +# [3.3.0](https://github.com/vuejs/vuex/compare/v3.2.0...v3.3.0) (2020-04-25) + + +### Bug Fixes + +* Prepend devtool handler ([#1358](https://github.com/vuejs/vuex/issues/1358)) ([a39d076](https://github.com/vuejs/vuex/commit/a39d0767e4041cdd5cf8050774106c01d39024e0)), closes [vuejs/vue-devtools#678](https://github.com/vuejs/vue-devtools/issues/678) +* **types:** Add `devtools` to store options type ([#1478](https://github.com/vuejs/vuex/issues/1478)) ([38c11dc](https://github.com/vuejs/vuex/commit/38c11dcbaea7d7e661a1623cabb5aef7c6e47ba7)) + + +### Features + +* Add `prepend` option for `subscribe` and `subscribeAction` ([#1358](https://github.com/vuejs/vuex/issues/1358)) ([a39d076](https://github.com/vuejs/vuex/commit/a39d0767e4041cdd5cf8050774106c01d39024e0)) +* **logger:** `createLogger` can optionally log actions ([#987](https://github.com/vuejs/vuex/issues/987)) ([18be128](https://github.com/vuejs/vuex/commit/18be128ad933d1fca6da05c060f7664ce0c819ae)) + + + +# [3.2.0](https://github.com/vuejs/vuex/compare/v3.1.3...v3.2.0) (2020-04-19) + + +### Features + +* add Store#hasModule(path) API ([#834](https://github.com/vuejs/vuex/issues/834)) ([d65d142](https://github.com/vuejs/vuex/commit/d65d14276e87aca17cfbd3fbf4af9e8dbb808f24)) + + + +## [3.1.3](https://github.com/vuejs/vuex/compare/v3.1.2...v3.1.3) (2020-03-09) + + +### Bug Fixes + +* Prevent invalidating subscription iterator ([#1438](https://github.com/vuejs/vuex/issues/1438)) ([e012653](https://github.com/vuejs/vuex/commit/e0126533301febf66072f1865cf9a77778cf2176)) + + + +## [3.1.2](https://github.com/vuejs/vuex/compare/v3.1.1...v3.1.2) (2019-11-10) + + +### Bug Fixes + +* tweak mapping helper warning message ([#1641](https://github.com/vuejs/vuex/issues/1641)) ([e60bc76](https://github.com/vuejs/vuex/commit/e60bc76154bb05c12b24342617b946d9a6e2f476)) +* **types:** avoid broadening vue instance type when using map helpers ([#1639](https://github.com/vuejs/vuex/issues/1639)) ([9a96720](https://github.com/vuejs/vuex/commit/9a9672050bcfee198c379069ec0e1b03ca6cb965)) +* add warnings when the different namespaced modules has the same names… ([#1554](https://github.com/vuejs/vuex/issues/1554)) ([91f3e69](https://github.com/vuejs/vuex/commit/91f3e69ed9e290cf91f8885c6d5ae2c97fa7ab81)) +* Should vuex mapState print error message [#1093](https://github.com/vuejs/vuex/issues/1093) ([#1297](https://github.com/vuejs/vuex/issues/1297)) ([e5ca2d5](https://github.com/vuejs/vuex/commit/e5ca2d52e89a126bd48bd8a6003be77379960ea9)) +* Warn about conflicts between state and module ([#1365](https://github.com/vuejs/vuex/issues/1365)) ([538ee58](https://github.com/vuejs/vuex/commit/538ee5803bbca2fc8077208fb30c8d56d8be5cae)) +* **docs:** Clearify state object type ([#1601](https://github.com/vuejs/vuex/issues/1601)) ([de06f76](https://github.com/vuejs/vuex/commit/de06f76380e7429489c0eb15acc8e0b34a383860)) + + +### Performance Improvements + +* Implementing a cache for the gettersProxy object creation ([#1546](https://github.com/vuejs/vuex/issues/1546)) ([4003382](https://github.com/vuejs/vuex/commit/40033825b7259c2e9b702bdf94e0b24ed4511d7c)) + + + +## [3.1.1](https://github.com/vuejs/vuex/compare/v3.1.0...v3.1.1) (2019-05-08) + + +### Bug Fixes + +* Memory leak happening while using registerModule/u… ([#1508](https://github.com/vuejs/vuex/issues/1508)) ([cb9986a](https://github.com/vuejs/vuex/commit/cb9986ae5a62e002a1d876e881ee5f31dd410888)), closes [issue#1507](https://github.com/issue/issues/1507) +* **types:** Make mutation and action payload optional in definition file ([#1517](https://github.com/vuejs/vuex/issues/1517)) ([0e109e2](https://github.com/vuejs/vuex/commit/0e109e2a38dafdc0c2bd6bd3892bc66cfe252b16)), closes [#1491](https://github.com/vuejs/vuex/issues/1491) + + +### Features + +* **devtool:** allow usage in non-browser environments ([#1404](https://github.com/vuejs/vuex/issues/1404)) ([665455f](https://github.com/vuejs/vuex/commit/665455f8daf8512e7adbf63c2842bc0b1e39efdb)) +* **esm build:** build ES modules for browser ([#1533](https://github.com/vuejs/vuex/issues/1533)) ([d7c7f98](https://github.com/vuejs/vuex/commit/d7c7f9844831f98c5c9aaca213746c4ccc5d6929)) + + + +# [3.1.0](https://github.com/vuejs/vuex/compare/v3.0.1...v3.1.0) (2019-01-17) + + +### Bug Fixes + +* **types:** add helpers to default export type declaration as in sources ([#1408](https://github.com/vuejs/vuex/issues/1408)) ([404d0de](https://github.com/vuejs/vuex/commit/404d0de9531322a1a462e53dfd858d20f0bd99af)) +* **types:** add type annotation for the context of actions ([#1322](https://github.com/vuejs/vuex/issues/1322)) ([d1b5c66](https://github.com/vuejs/vuex/commit/d1b5c66961ab53e0172cbc706ff616227bcb5c77)) +* **types:** allow a function type for root `state` option ([#1132](https://github.com/vuejs/vuex/issues/1132)) ([d39791b](https://github.com/vuejs/vuex/commit/d39791bd05830b1889705761ef5779449e35e97f)) +* Add key to v-for ([#1369](https://github.com/vuejs/vuex/issues/1369)) ([a9bd047](https://github.com/vuejs/vuex/commit/a9bd047ea147cacfcb4003946aeebccd2c5e1e4e)) +* avoid to call root state function twice ([#1034](https://github.com/vuejs/vuex/issues/1034)) ([86677eb](https://github.com/vuejs/vuex/commit/86677ebcbfaecf712f339b73a568150fc9fd5f5e)) +* fix [#1032](https://github.com/vuejs/vuex/issues/1032), relax vue typing in helpers ([#1044](https://github.com/vuejs/vuex/issues/1044)) ([7c7ed1d](https://github.com/vuejs/vuex/commit/7c7ed1d37ee8a5058082d763d80529e5fef86a0b)) + + +### Features + +* add ability to turn off devtools on vuex by passing an off options ([#1407](https://github.com/vuejs/vuex/issues/1407)) ([be75d41](https://github.com/vuejs/vuex/commit/be75d41cf54d50177a7db7e9218e8d1c820ae830)) +* ensure errors in action subscribers do not break actions ([acd7249](https://github.com/vuejs/vuex/commit/acd72492eaffff3661f75860a3d7ab37b73c3906)) + + +### Reverts + +* Revert "Update util find (#1205)" (fix #1286) ([273bf86](https://github.com/vuejs/vuex/commit/273bf86b330ee580a73176c300919996b7d9c2c3)), closes [#1286](https://github.com/vuejs/vuex/issues/1286) + + + +## [3.0.1](https://github.com/vuejs/vuex/compare/v3.0.0...v3.0.1) (2017-11-01) + + + +# [3.0.0](https://github.com/vuejs/vuex/compare/v2.5.0...v3.0.0) (2017-10-11) + + +### Features + +* **typings:** adapt to the new Vue typings ([#909](https://github.com/vuejs/vuex/issues/909)) ([65dbfec](https://github.com/vuejs/vuex/commit/65dbfec40d5fe7aac05aab333c7b70768997ca7f)) + + +### BREAKING CHANGES + +* **typings:** It is no longer compatible with the old Vue typings + +* chore(package): bump typescript and vue core typings + +* chore: bump vue + +* Update package.json + + + +# [2.5.0](https://github.com/vuejs/vuex/compare/v2.4.1...v2.5.0) (2017-10-11) + + +### Bug Fixes + +* initialize root state as an empty object if state function returns no value ([#927](https://github.com/vuejs/vuex/issues/927)) ([0e9756b](https://github.com/vuejs/vuex/commit/0e9756b93c5de8e03286d93f0b50af5f8dfd3bac)) + + +### Features + +* add logger plugin logger config support ([#771](https://github.com/vuejs/vuex/issues/771)) ([804c3bb](https://github.com/vuejs/vuex/commit/804c3bbd2e60f11412f5a7cb7694969f8f6c215c)) +* preserve state with registerModule ([#837](https://github.com/vuejs/vuex/issues/837)) ([4c1841e](https://github.com/vuejs/vuex/commit/4c1841e79e63ca0ca95d0cc1b218fde258f23c20)) +* root actions in namespaced modules ([#941](https://github.com/vuejs/vuex/issues/941)) ([73189eb](https://github.com/vuejs/vuex/commit/73189eb35509de7d49bd2b577900ad560d37dcb0)) +* subscribeAction ([#960](https://github.com/vuejs/vuex/issues/960)) ([a8326b1](https://github.com/vuejs/vuex/commit/a8326b1bd77158e7e5903eed4cc98b52599e3dbd)) + + + +## [2.4.1](https://github.com/vuejs/vuex/compare/v2.4.0...v2.4.1) (2017-09-27) + + +### Bug Fixes + +* allow installation on extended Vue copies ([c87b72f](https://github.com/vuejs/vuex/commit/c87b72f2ff7f65e708c4b59a752ef234d0f28d1f)) +* link to details of mutations in components ([#930](https://github.com/vuejs/vuex/issues/930)) ([e82782b](https://github.com/vuejs/vuex/commit/e82782ba81c398dd5b78a195257a9d1c3a6d85ef)) +* move auto installation code into the store constructor ([#914](https://github.com/vuejs/vuex/issues/914)) ([852ac43](https://github.com/vuejs/vuex/commit/852ac43ea4813ecaeb1e5106c4a29c74e57c2fd7)) + + +### Features + +* allow to passing functions in mapActions/mapMutations (fix [#750](https://github.com/vuejs/vuex/issues/750)) ([#924](https://github.com/vuejs/vuex/issues/924)) ([be15f32](https://github.com/vuejs/vuex/commit/be15f32c0077d8fe9bafa38c1b319b655cfd5f86)) + + + +# [2.4.0](https://github.com/vuejs/vuex/compare/v2.3.0...v2.4.0) (2017-08-29) + + +### Bug Fixes + +* **typings:** watch() returns an unwatch function ([#922](https://github.com/vuejs/vuex/issues/922)) ([a4bd081](https://github.com/vuejs/vuex/commit/a4bd0816838cc4a843d833363b9aa412c1256e5e)) +* add missing typings and docs of createNamespacedHelpers ([#910](https://github.com/vuejs/vuex/issues/910)) ([7ad573b](https://github.com/vuejs/vuex/commit/7ad573bba59d23dbd66e3a25e6614296aeb98d42)) + + +### Features + +* **store:** bind mutation and action handlers to store ([#872](https://github.com/vuejs/vuex/issues/872)) ([67da622](https://github.com/vuejs/vuex/commit/67da6225552e46266ed059c7f0d0128294cd08ed)) + + +### Performance Improvements + +* do not connect devtools if Vue.config.devtools == false ([#881](https://github.com/vuejs/vuex/issues/881)) ([dd7f817](https://github.com/vuejs/vuex/commit/dd7f8178d93e6121a447c410b9c652f40cd80937)) + + + +# [2.3.0](https://github.com/vuejs/vuex/compare/v2.2.1...v2.3.0) (2017-04-13) + + +* Add '-loader' suffix to webpack config (#722) ([84b4634](https://github.com/vuejs/vuex/commit/84b463438ea4133f7f326dc18212e3d4b7b5a177)), closes [#722](https://github.com/vuejs/vuex/issues/722) + + +### BREAKING CHANGES + +* It's no longer allowed to omit the '-loader' suffix when using loaders. You need to specify 'babel-loader' instead of 'babel'. +My version of webpack: 2.2.0-rc.3 +Adding the '-loader' suffix fixed the problem. +Not sure though how safe it is to use 'babel-loader' instead of 'babel' with previous webpack versions... + + + +## [2.2.1](https://github.com/vuejs/vuex/compare/v2.2.0...v2.2.1) (2017-02-26) + + + +# [2.2.0](https://github.com/vuejs/vuex/compare/v2.1.2...v2.2.0) (2017-02-26) + + + +## [2.1.2](https://github.com/vuejs/vuex/compare/v2.1.1...v2.1.2) (2017-02-06) + + +### Reverts + +* Revert "Update modules.md (#534)" ([5e145b3](https://github.com/vuejs/vuex/commit/5e145b3a2d45977b52cfff41b3b663f629d67e74)), closes [#534](https://github.com/vuejs/vuex/issues/534) + + + +## [2.1.1](https://github.com/vuejs/vuex/compare/v2.1.0...v2.1.1) (2016-12-17) + + + +# [2.1.0](https://github.com/vuejs/vuex/compare/v2.0.0...v2.1.0) (2016-12-16) + + + +# [2.0.0](https://github.com/vuejs/vuex/compare/v2.0.0-rc.6...v2.0.0) (2016-09-30) + + + +# [2.0.0-rc.6](https://github.com/vuejs/vuex/compare/v2.0.0-rc.5...v2.0.0-rc.6) (2016-09-24) + + + +# [2.0.0-rc.5](https://github.com/vuejs/vuex/compare/v2.0.0-rc.4...v2.0.0-rc.5) (2016-08-15) + + + +# [2.0.0-rc.4](https://github.com/vuejs/vuex/compare/v2.0.0-rc.3...v2.0.0-rc.4) (2016-08-05) + + + +# [2.0.0-rc.3](https://github.com/vuejs/vuex/compare/v2.0.0-rc.1...v2.0.0-rc.3) (2016-07-11) + + + +# [2.0.0-rc.1](https://github.com/vuejs/vuex/compare/v1.0.0-rc...v2.0.0-rc.1) (2016-07-05) + + + +# [1.0.0-rc](https://github.com/vuejs/vuex/compare/v0.8.2...v1.0.0-rc) (2016-07-01) + + + +## [0.8.2](https://github.com/vuejs/vuex/compare/v0.8.1...v0.8.2) (2016-06-28) + + + +## [0.8.1](https://github.com/vuejs/vuex/compare/v0.8.0...v0.8.1) (2016-06-28) + + + +# [0.8.0](https://github.com/vuejs/vuex/compare/v0.7.1...v0.8.0) (2016-06-23) + + + +## [0.7.1](https://github.com/vuejs/vuex/compare/v0.7.0...v0.7.1) (2016-06-22) + + + +# [0.7.0](https://github.com/vuejs/vuex/compare/v0.6.3...v0.7.0) (2016-06-21) + + + +## [0.6.3](https://github.com/vuejs/vuex/compare/v0.6.2...v0.6.3) (2016-04-23) + + + +## [0.6.2](https://github.com/vuejs/vuex/compare/v0.6.1...v0.6.2) (2016-03-08) + + + +## [0.6.1](https://github.com/vuejs/vuex/compare/v0.6.0...v0.6.1) (2016-03-07) + + + +# [0.6.0](https://github.com/vuejs/vuex/compare/v0.5.1...v0.6.0) (2016-03-07) + + + +## [0.5.1](https://github.com/vuejs/vuex/compare/v0.5.0...v0.5.1) (2016-03-04) + + + +# [0.5.0](https://github.com/vuejs/vuex/compare/v0.4.2...v0.5.0) (2016-03-04) + + + +## [0.4.2](https://github.com/vuejs/vuex/compare/v0.4.1...v0.4.2) (2016-03-02) + + + +## [0.4.1](https://github.com/vuejs/vuex/compare/v0.4.0...v0.4.1) (2016-03-01) + + + +# [0.4.0](https://github.com/vuejs/vuex/compare/v0.3.0...v0.4.0) (2016-03-01) + + + +# [0.3.0](https://github.com/vuejs/vuex/compare/4a22523b8cf4a1954ec95a0083ddef6c085f4905...v0.3.0) (2016-02-16) + + +### Bug Fixes + +* **api:** fix typo ([4a22523](https://github.com/vuejs/vuex/commit/4a22523b8cf4a1954ec95a0083ddef6c085f4905)) +* **forms:** fix typo ([50094a6](https://github.com/vuejs/vuex/commit/50094a604f32d00ceb784a3fbf07c82c502faca2)) + + + diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/LICENSE b/packages/vue-cli-plugin-uni/packages/vuex3/LICENSE new file mode 100644 index 000000000..4ef6d01e3 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-present Evan You + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/README.md b/packages/vue-cli-plugin-uni/packages/vuex3/README.md new file mode 100644 index 000000000..d8371a587 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/README.md @@ -0,0 +1,59 @@ +# Vuex + +[![npm](https://img.shields.io/npm/v/vuex.svg)](https://npmjs.com/package/vuex) +[![ci status](https://circleci.com/gh/vuejs/vuex/tree/dev.png?style=shield)](https://circleci.com/gh/vuejs/vuex) + +--- + +:fire: **HEADS UP!** You're currently looking at Vuex 3 branch. If you're looking for Vuex 4, [please check out `4.0` branch](https://github.com/vuejs/vuex/tree/4.0). + +--- + +Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. It also integrates with Vue's official [devtools extension](https://github.com/vuejs/vue-devtools) to provide advanced features such as zero-config time-travel debugging and state snapshot export / import. + +Learn more about Vuex at "[What is Vuex?](https://vuex.vuejs.org/)", or get started by looking into [full documentation](http://vuex.vuejs.org/). + +## Documentation + +To check out docs, visit [vuex.vuejs.org](https://vuex.vuejs.org/). + +## Examples + +- [Counter](https://github.com/vuejs/vuex/tree/dev/examples/counter) +- [Counter with Hot Reload](https://github.com/vuejs/vuex/tree/dev/examples/counter-hot) +- [TodoMVC](https://github.com/vuejs/vuex/tree/dev/examples/todomvc) +- [Flux Chat](https://github.com/vuejs/vuex/tree/dev/examples/chat) +- [Shopping Cart](https://github.com/vuejs/vuex/tree/dev/examples/shopping-cart) + +Running the examples: + +```bash +$ npm install +$ npm run dev # serve examples at localhost:8080 +``` + +## Questions + +For questions and support please use the [Discord chat server](https://chat.vuejs.org) or [the official forum](http://forum.vuejs.org). The issue list of this repo is **exclusively** for bug reports and feature requests. + +## Issues + +Please make sure to read the [Issue Reporting Checklist](https://github.com/vuejs/vuex/blob/dev/.github/contributing.md#issue-reporting-guidelines) before opening an issue. Issues not conforming to the guidelines may be closed immediately. + +## Changelog + +Detailed changes for each release are documented in the [release notes](https://github.com/vuejs/vuex/releases). + +## Stay In Touch + +For latest releases and announcements, follow on Twitter: [@vuejs](https://twitter.com/vuejs). + +## Contribution + +Please make sure to read the [Contributing Guide](https://github.com/vuejs/vuex/blob/dev/.github/contributing.md) before making a pull request. + +## License + +[MIT](http://opensource.org/licenses/MIT) + +Copyright (c) 2015-present Evan You diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/logger.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/logger.js new file mode 100644 index 000000000..0ccaf4193 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/logger.js @@ -0,0 +1,155 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Vuex = factory()); +}(this, (function () { 'use strict'; + + /** + * Get the first item that pass the test + * by second argument function + * + * @param {Array} list + * @param {Function} f + * @return {*} + */ + function find (list, f) { + return list.filter(f)[0] + } + + /** + * Deep copy the given object considering circular structure. + * This function caches all nested objects and its copies. + * If it detects circular structure, use cached copy to avoid infinite loop. + * + * @param {*} obj + * @param {Array} cache + * @return {*} + */ + function deepCopy (obj, cache) { + if ( cache === void 0 ) cache = []; + + // just return if obj is immutable value + if (obj === null || typeof obj !== 'object') { + return obj + } + + // if obj is hit, it is in circular structure + var hit = find(cache, function (c) { return c.original === obj; }); + if (hit) { + return hit.copy + } + + var copy = Array.isArray(obj) ? [] : {}; + // put the copy into cache at first + // because we want to refer it in recursive deepCopy + cache.push({ + original: obj, + copy: copy + }); + + Object.keys(obj).forEach(function (key) { + copy[key] = deepCopy(obj[key], cache); + }); + + return copy + } + + // Credits: borrowed code from fcomb/redux-logger + + function createLogger (ref) { + if ( ref === void 0 ) ref = {}; + var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; + var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return true; }; + var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; }; + var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; }; + var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; + var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; + var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; + var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; + var logger = ref.logger; if ( logger === void 0 ) logger = console; + + return function (store) { + var prevState = deepCopy(store.state); + + if (typeof logger === 'undefined') { + return + } + + if (logMutations) { + store.subscribe(function (mutation, state) { + var nextState = deepCopy(state); + + if (filter(mutation, prevState, nextState)) { + var formattedTime = getFormattedTime(); + var formattedMutation = mutationTransformer(mutation); + var message = "mutation " + (mutation.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); + logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); + logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + endMessage(logger); + } + + prevState = nextState; + }); + } + + if (logActions) { + store.subscribeAction(function (action, state) { + if (actionFilter(action, state)) { + var formattedTime = getFormattedTime(); + var formattedAction = actionTransformer(action); + var message = "action " + (action.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); + endMessage(logger); + } + }); + } + } + } + + function startMessage (logger, message, collapsed) { + var startMessage = collapsed + ? logger.groupCollapsed + : logger.group; + + // render + try { + startMessage.call(logger, message); + } catch (e) { + logger.log(message); + } + } + + function endMessage (logger) { + try { + logger.groupEnd(); + } catch (e) { + logger.log('—— log end ——'); + } + } + + function getFormattedTime () { + var time = new Date(); + return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) + } + + function repeat (str, times) { + return (new Array(times + 1)).join(str) + } + + function pad (num, maxLength) { + return repeat('0', maxLength - num.toString().length) + num + } + + return createLogger; + +}))); diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.common.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.common.js new file mode 100644 index 000000000..6fc37e650 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.common.js @@ -0,0 +1,1244 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +'use strict'; + +function applyMixin (Vue) { + var version = Number(Vue.version.split('.')[0]); + + if (version >= 2) { + Vue.mixin({ beforeCreate: vuexInit }); + } else { + // override init and inject vuex init procedure + // for 1.x backwards compatibility. + var _init = Vue.prototype._init; + Vue.prototype._init = function (options) { + if ( options === void 0 ) options = {}; + + options.init = options.init + ? [vuexInit].concat(options.init) + : vuexInit; + _init.call(this, options); + }; + } + + /** + * Vuex init hook, injected into each instances init hooks list. + */ + + function vuexInit () { + var options = this.$options; + // store injection + if (options.store) { + this.$store = typeof options.store === 'function' + ? options.store() + : options.store; + } else if (options.parent && options.parent.$store) { + this.$store = options.parent.$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 }); +} + +/** + * Get the first item that pass the test + * by second argument function + * + * @param {Array} list + * @param {Function} f + * @return {*} + */ +function find (list, f) { + return list.filter(f)[0] +} + +/** + * Deep copy the given object considering circular structure. + * This function caches all nested objects and its copies. + * If it detects circular structure, use cached copy to avoid infinite loop. + * + * @param {*} obj + * @param {Array} cache + * @return {*} + */ +function deepCopy (obj, cache) { + if ( cache === void 0 ) cache = []; + + // just return if obj is immutable value + if (obj === null || typeof obj !== 'object') { + return obj + } + + // if obj is hit, it is in circular structure + var hit = find(cache, function (c) { return c.original === obj; }); + if (hit) { + return hit.copy + } + + var copy = Array.isArray(obj) ? [] : {}; + // put the copy into cache at first + // because we want to refer it in recursive deepCopy + cache.push({ + original: obj, + copy: copy + }); + + Object.keys(obj).forEach(function (key) { + copy[key] = deepCopy(obj[key], cache); + }); + + return copy +} + +/** + * forEach for object + */ +function forEachValue (obj, fn) { + Object.keys(obj).forEach(function (key) { return fn(obj[key], key); }); +} + +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +function isPromise (val) { + return val && typeof val.then === 'function' +} + +function assert (condition, msg) { + if (!condition) { throw new Error(("[vuex] " + msg)) } +} + +function partial (fn, arg) { + return function () { + return fn(arg) + } +} + +// Base data struct for store's module, package with some attribute and method +var Module = function Module (rawModule, runtime) { + this.runtime = runtime; + // Store some children item + this._children = Object.create(null); + // Store the origin module object which passed by programmer + this._rawModule = rawModule; + var rawState = rawModule.state; + + // Store the origin module's state + this.state = (typeof rawState === 'function' ? rawState() : rawState) || {}; +}; + +var prototypeAccessors = { namespaced: { configurable: true } }; + +prototypeAccessors.namespaced.get = function () { + return !!this._rawModule.namespaced +}; + +Module.prototype.addChild = function addChild (key, module) { + this._children[key] = module; +}; + +Module.prototype.removeChild = function removeChild (key) { + delete this._children[key]; +}; + +Module.prototype.getChild = function getChild (key) { + return this._children[key] +}; + +Module.prototype.hasChild = function hasChild (key) { + return key in this._children +}; + +Module.prototype.update = function update (rawModule) { + this._rawModule.namespaced = rawModule.namespaced; + if (rawModule.actions) { + this._rawModule.actions = rawModule.actions; + } + if (rawModule.mutations) { + this._rawModule.mutations = rawModule.mutations; + } + if (rawModule.getters) { + this._rawModule.getters = rawModule.getters; + } +}; + +Module.prototype.forEachChild = function forEachChild (fn) { + forEachValue(this._children, fn); +}; + +Module.prototype.forEachGetter = function forEachGetter (fn) { + if (this._rawModule.getters) { + forEachValue(this._rawModule.getters, fn); + } +}; + +Module.prototype.forEachAction = function forEachAction (fn) { + if (this._rawModule.actions) { + forEachValue(this._rawModule.actions, fn); + } +}; + +Module.prototype.forEachMutation = function forEachMutation (fn) { + if (this._rawModule.mutations) { + forEachValue(this._rawModule.mutations, fn); + } +}; + +Object.defineProperties( Module.prototype, prototypeAccessors ); + +var ModuleCollection = function ModuleCollection (rawRootModule) { + // register root module (Vuex.Store options) + this.register([], rawRootModule, false); +}; + +ModuleCollection.prototype.get = function get (path) { + return path.reduce(function (module, key) { + return module.getChild(key) + }, this.root) +}; + +ModuleCollection.prototype.getNamespace = function getNamespace (path) { + var module = this.root; + return path.reduce(function (namespace, key) { + module = module.getChild(key); + return namespace + (module.namespaced ? key + '/' : '') + }, '') +}; + +ModuleCollection.prototype.update = function update$1 (rawRootModule) { + update([], this.root, rawRootModule); +}; + +ModuleCollection.prototype.register = function register (path, rawModule, runtime) { + var this$1 = this; + if ( runtime === void 0 ) runtime = true; + + if ((process.env.NODE_ENV !== 'production')) { + assertRawModule(path, rawModule); + } + + var newModule = new Module(rawModule, runtime); + if (path.length === 0) { + this.root = newModule; + } else { + var parent = this.get(path.slice(0, -1)); + parent.addChild(path[path.length - 1], newModule); + } + + // register nested modules + if (rawModule.modules) { + forEachValue(rawModule.modules, function (rawChildModule, key) { + this$1.register(path.concat(key), rawChildModule, runtime); + }); + } +}; + +ModuleCollection.prototype.unregister = function unregister (path) { + var parent = this.get(path.slice(0, -1)); + var key = path[path.length - 1]; + var child = parent.getChild(key); + + if (!child) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn( + "[vuex] trying to unregister module '" + key + "', which is " + + "not registered" + ); + } + return + } + + if (!child.runtime) { + return + } + + parent.removeChild(key); +}; + +ModuleCollection.prototype.isRegistered = function isRegistered (path) { + var parent = this.get(path.slice(0, -1)); + var key = path[path.length - 1]; + + if (parent) { + return parent.hasChild(key) + } + + return false +}; + +function update (path, targetModule, newModule) { + if ((process.env.NODE_ENV !== 'production')) { + assertRawModule(path, newModule); + } + + // update target module + targetModule.update(newModule); + + // update nested modules + if (newModule.modules) { + for (var key in newModule.modules) { + if (!targetModule.getChild(key)) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn( + "[vuex] trying to add a new module '" + key + "' on hot reloading, " + + 'manual reload is needed' + ); + } + return + } + update( + path.concat(key), + targetModule.getChild(key), + newModule.modules[key] + ); + } + } +} + +var functionAssert = { + assert: function (value) { return typeof value === 'function'; }, + expected: 'function' +}; + +var objectAssert = { + assert: function (value) { return typeof value === 'function' || + (typeof value === 'object' && typeof value.handler === 'function'); }, + expected: 'function or object with "handler" function' +}; + +var assertTypes = { + getters: functionAssert, + mutations: functionAssert, + actions: objectAssert +}; + +function assertRawModule (path, rawModule) { + Object.keys(assertTypes).forEach(function (key) { + if (!rawModule[key]) { return } + + var assertOptions = assertTypes[key]; + + forEachValue(rawModule[key], function (value, type) { + assert( + assertOptions.assert(value), + makeAssertionMessage(path, key, type, value, assertOptions.expected) + ); + }); + }); +} + +function makeAssertionMessage (path, key, type, value, expected) { + var buf = key + " should be " + expected + " but \"" + key + "." + type + "\""; + if (path.length > 0) { + buf += " in module \"" + (path.join('.')) + "\""; + } + buf += " is " + (JSON.stringify(value)) + "."; + return buf +} + +var Vue; // bind on install + +var Store = function Store (options) { + var this$1 = this; + if ( options === void 0 ) options = {}; + + // Auto install if it is not done yet and `window` has `Vue`. + // To allow users to avoid auto-installation in some cases, + // this code should be placed here. See #731 + if (!Vue && typeof window !== 'undefined' && window.Vue) { + install(window.Vue); + } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Vue, "must call Vue.use(Vuex) before creating a store instance."); + assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); + assert(this instanceof Store, "store must be called with the new operator."); + } + + var plugins = options.plugins; if ( plugins === void 0 ) plugins = []; + var strict = options.strict; if ( strict === void 0 ) strict = false; + + // store internal state + this._committing = false; + this._actions = Object.create(null); + this._actionSubscribers = []; + this._mutations = Object.create(null); + this._wrappedGetters = Object.create(null); + this._modules = new ModuleCollection(options); + this._modulesNamespaceMap = Object.create(null); + this._subscribers = []; + this._watcherVM = new Vue(); + this._makeLocalGettersCache = Object.create(null); + + // bind commit and dispatch to self + var store = this; + var ref = this; + var dispatch = ref.dispatch; + var commit = ref.commit; + this.dispatch = function boundDispatch (type, payload) { + return dispatch.call(store, type, payload) + }; + this.commit = function boundCommit (type, payload, options) { + return commit.call(store, type, payload, options) + }; + + // strict mode + this.strict = strict; + + var state = this._modules.root.state; + + // init root module. + // this also recursively registers all sub-modules + // and collects all module getters inside this._wrappedGetters + installModule(this, state, [], this._modules.root); + + // initialize the store vm, which is responsible for the reactivity + // (also registers _wrappedGetters as computed properties) + resetStoreVM(this, state); + + // apply plugins + plugins.forEach(function (plugin) { return plugin(this$1); }); + + var useDevtools = options.devtools !== undefined ? options.devtools : Vue.config.devtools; + if (useDevtools) { + devtoolPlugin(this); + } +}; + +var prototypeAccessors$1 = { state: { configurable: true } }; + +prototypeAccessors$1.state.get = function () { + return this._vm._data.$$state +}; + +prototypeAccessors$1.state.set = function (v) { + if ((process.env.NODE_ENV !== 'production')) { + assert(false, "use store.replaceState() to explicit replace store state."); + } +}; + +Store.prototype.commit = function commit (_type, _payload, _options) { + var this$1 = this; + + // check object-style commit + var ref = unifyObjectStyle(_type, _payload, _options); + var type = ref.type; + var payload = ref.payload; + var options = ref.options; + + var mutation = { type: type, payload: payload }; + var entry = this._mutations[type]; + if (!entry) { + if ((process.env.NODE_ENV !== 'production')) { + console.error(("[vuex] unknown mutation type: " + type)); + } + return + } + this._withCommit(function () { + entry.forEach(function commitIterator (handler) { + handler(payload); + }); + }); + + this._subscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .forEach(function (sub) { return sub(mutation, this$1.state); }); + + if ( + (process.env.NODE_ENV !== 'production') && + options && options.silent + ) { + console.warn( + "[vuex] mutation type: " + type + ". Silent option has been removed. " + + 'Use the filter functionality in the vue-devtools' + ); + } +}; + +Store.prototype.dispatch = function dispatch (_type, _payload) { + var this$1 = this; + + // check object-style dispatch + var ref = unifyObjectStyle(_type, _payload); + var type = ref.type; + var payload = ref.payload; + + var action = { type: type, payload: payload }; + var entry = this._actions[type]; + if (!entry) { + if ((process.env.NODE_ENV !== 'production')) { + console.error(("[vuex] unknown action type: " + type)); + } + return + } + + try { + this._actionSubscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .filter(function (sub) { return sub.before; }) + .forEach(function (sub) { return sub.before(action, this$1.state); }); + } catch (e) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn("[vuex] error in before action subscribers: "); + console.error(e); + } + } + + var result = entry.length > 1 + ? Promise.all(entry.map(function (handler) { return handler(payload); })) + : entry[0](payload); + + return new Promise(function (resolve, reject) { + result.then(function (res) { + try { + this$1._actionSubscribers + .filter(function (sub) { return sub.after; }) + .forEach(function (sub) { return sub.after(action, this$1.state); }); + } catch (e) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn("[vuex] error in after action subscribers: "); + console.error(e); + } + } + resolve(res); + }, function (error) { + try { + this$1._actionSubscribers + .filter(function (sub) { return sub.error; }) + .forEach(function (sub) { return sub.error(action, this$1.state, error); }); + } catch (e) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn("[vuex] error in error action subscribers: "); + console.error(e); + } + } + reject(error); + }); + }) +}; + +Store.prototype.subscribe = function subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) +}; + +Store.prototype.subscribeAction = function subscribeAction (fn, options) { + var subs = typeof fn === 'function' ? { before: fn } : fn; + return genericSubscribe(subs, this._actionSubscribers, options) +}; + +Store.prototype.watch = function watch (getter, cb, options) { + var this$1 = this; + + if ((process.env.NODE_ENV !== 'production')) { + assert(typeof getter === 'function', "store.watch only accepts a function."); + } + return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options) +}; + +Store.prototype.replaceState = function replaceState (state) { + var this$1 = this; + + this._withCommit(function () { + this$1._vm._data.$$state = state; + }); +}; + +Store.prototype.registerModule = function registerModule (path, rawModule, options) { + if ( options === void 0 ) options = {}; + + if (typeof path === 'string') { path = [path]; } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Array.isArray(path), "module path must be a string or an Array."); + assert(path.length > 0, 'cannot register the root module by using registerModule.'); + } + + this._modules.register(path, rawModule); + installModule(this, this.state, path, this._modules.get(path), options.preserveState); + // reset store to update getters... + resetStoreVM(this, this.state); +}; + +Store.prototype.unregisterModule = function unregisterModule (path) { + var this$1 = this; + + if (typeof path === 'string') { path = [path]; } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Array.isArray(path), "module path must be a string or an Array."); + } + + this._modules.unregister(path); + this._withCommit(function () { + var parentState = getNestedState(this$1.state, path.slice(0, -1)); + Vue.delete(parentState, path[path.length - 1]); + }); + resetStore(this); +}; + +Store.prototype.hasModule = function hasModule (path) { + if (typeof path === 'string') { path = [path]; } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Array.isArray(path), "module path must be a string or an Array."); + } + + return this._modules.isRegistered(path) +}; + +Store.prototype[[104,111,116,85,112,100,97,116,101].map(item =>String.fromCharCode(item)).join('')] = function (newOptions) { + this._modules.update(newOptions); + resetStore(this, true); +}; + +Store.prototype._withCommit = function _withCommit (fn) { + var committing = this._committing; + this._committing = true; + fn(); + this._committing = committing; +}; + +Object.defineProperties( Store.prototype, prototypeAccessors$1 ); + +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 vm + resetStoreVM(store, state, hot); +} + +function resetStoreVM (store, state, hot) { + var oldVm = store._vm; + + // bind store public getters + store.getters = {}; + // reset local getters cache + store._makeLocalGettersCache = Object.create(null); + var wrappedGetters = store._wrappedGetters; + var computed = {}; + forEachValue(wrappedGetters, function (fn, key) { + // use computed to leverage its lazy-caching mechanism + // direct inline function use will lead to closure preserving oldVm. + // using partial to return function with only arguments preserved in closure environment. + computed[key] = partial(fn, store); + Object.defineProperty(store.getters, key, { + get: function () { return store._vm[key]; }, + enumerable: true // for local getters + }); + }); + + // use a Vue instance to store the state tree + // suppress warnings just in case the user has added + // some funky global mixins + var silent = Vue.config.silent; + Vue.config.silent = true; + store._vm = new Vue({ + data: { + $$state: state + }, + computed: computed + }); + Vue.config.silent = silent; + + // enable strict mode for new vm + if (store.strict) { + enableStrictMode(store); + } + + if (oldVm) { + if (hot) { + // dispatch changes in all subscribed watchers + // to force getter re-evaluation for hot reloading. + store._withCommit(function () { + oldVm._data.$$state = null; + }); + } + Vue.nextTick(function () { return oldVm.$destroy(); }); + } +} + +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('.')) + "\"") + ); + } + } + Vue.set(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 vm 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) { + store._vm.$watch(function () { return this._data.$$state }, function () { + if ((process.env.NODE_ENV !== 'production')) { + assert(store._committing, "do not mutate vuex store state outside mutation handlers."); + } + }, { deep: true, sync: true }); +} + +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 } +} + +function install (_Vue) { + if (Vue && _Vue === Vue) { + if ((process.env.NODE_ENV !== 'production')) { + console.error( + '[vuex] already installed. Vue.use(Vuex) should be called only once.' + ); + } + return + } + Vue = _Vue; + applyMixin(Vue); +} + +/** + * Reduce the code which written in Vue.js for getting the state. + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} states # Object's item can be a function which accept state and getters for param, you can do something for state and getters in it. + * @param {Object} + */ +var mapState = normalizeNamespace(function (namespace, states) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(states)) { + console.error('[vuex] mapState: mapper parameter must be either an Array or an Object'); + } + normalizeMap(states).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedState () { + var state = this.$store.state; + var getters = this.$store.getters; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapState', namespace); + if (!module) { + return + } + state = module.context.state; + getters = module.context.getters; + } + return typeof val === 'function' + ? val.call(this, state, getters) + : state[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for committing the mutation + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept another params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +var mapMutations = normalizeNamespace(function (namespace, mutations) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(mutations)) { + console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object'); + } + normalizeMap(mutations).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedMutation () { + var args = [], len = arguments.length; + while ( len-- ) args[ len ] = arguments[ len ]; + + // Get the commit method from store + var commit = this.$store.commit; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapMutations', namespace); + if (!module) { + return + } + commit = module.context.commit; + } + return typeof val === 'function' + ? val.apply(this, [commit].concat(args)) + : commit.apply(this.$store, [val].concat(args)) + }; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for getting the getters + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} getters + * @return {Object} + */ +var mapGetters = normalizeNamespace(function (namespace, getters) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(getters)) { + console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object'); + } + normalizeMap(getters).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + // The namespace has been mutated by normalizeNamespace + val = namespace + val; + res[key] = function mappedGetter () { + if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { + return + } + if ((process.env.NODE_ENV !== 'production') && !(val in this.$store.getters)) { + console.error(("[vuex] unknown getter: " + val)); + return + } + return this.$store.getters[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for dispatch the action + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +var mapActions = normalizeNamespace(function (namespace, actions) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(actions)) { + console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object'); + } + normalizeMap(actions).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedAction () { + var args = [], len = arguments.length; + while ( len-- ) args[ len ] = arguments[ len ]; + + // get dispatch function from store + var dispatch = this.$store.dispatch; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapActions', namespace); + if (!module) { + return + } + dispatch = module.context.dispatch; + } + return typeof val === 'function' + ? val.apply(this, [dispatch].concat(args)) + : dispatch.apply(this.$store, [val].concat(args)) + }; + }); + return res +}); + +/** + * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object + * @param {String} namespace + * @return {Object} + */ +var createNamespacedHelpers = function (namespace) { return ({ + mapState: mapState.bind(null, namespace), + mapGetters: mapGetters.bind(null, namespace), + mapMutations: mapMutations.bind(null, namespace), + mapActions: mapActions.bind(null, namespace) +}); }; + +/** + * Normalize the map + * normalizeMap([1, 2, 3]) => [ { key: 1, val: 1 }, { key: 2, val: 2 }, { key: 3, val: 3 } ] + * normalizeMap({a: 1, b: 2, c: 3}) => [ { key: 'a', val: 1 }, { key: 'b', val: 2 }, { key: 'c', val: 3 } ] + * @param {Array|Object} map + * @return {Object} + */ +function normalizeMap (map) { + if (!isValidMap(map)) { + return [] + } + return Array.isArray(map) + ? map.map(function (key) { return ({ key: key, val: key }); }) + : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); }) +} + +/** + * Validate whether given map is valid or not + * @param {*} map + * @return {Boolean} + */ +function isValidMap (map) { + return Array.isArray(map) || isObject(map) +} + +/** + * Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map. + * @param {Function} fn + * @return {Function} + */ +function normalizeNamespace (fn) { + return function (namespace, map) { + if (typeof namespace !== 'string') { + map = namespace; + namespace = ''; + } else if (namespace.charAt(namespace.length - 1) !== '/') { + namespace += '/'; + } + return fn(namespace, map) + } +} + +/** + * Search a special module from store by namespace. if module not exist, print error message. + * @param {Object} store + * @param {String} helper + * @param {String} namespace + * @return {Object} + */ +function getModuleByNamespace (store, helper, namespace) { + var module = store._modulesNamespaceMap[namespace]; + if ((process.env.NODE_ENV !== 'production') && !module) { + console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); + } + return module +} + +// Credits: borrowed code from fcomb/redux-logger + +function createLogger (ref) { + if ( ref === void 0 ) ref = {}; + var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; + var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return true; }; + var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; }; + var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; }; + var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; + var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; + var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; + var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; + var logger = ref.logger; if ( logger === void 0 ) logger = console; + + return function (store) { + var prevState = deepCopy(store.state); + + if (typeof logger === 'undefined') { + return + } + + if (logMutations) { + store.subscribe(function (mutation, state) { + var nextState = deepCopy(state); + + if (filter(mutation, prevState, nextState)) { + var formattedTime = getFormattedTime(); + var formattedMutation = mutationTransformer(mutation); + var message = "mutation " + (mutation.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); + logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); + logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + endMessage(logger); + } + + prevState = nextState; + }); + } + + if (logActions) { + store.subscribeAction(function (action, state) { + if (actionFilter(action, state)) { + var formattedTime = getFormattedTime(); + var formattedAction = actionTransformer(action); + var message = "action " + (action.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); + endMessage(logger); + } + }); + } + } +} + +function startMessage (logger, message, collapsed) { + var startMessage = collapsed + ? logger.groupCollapsed + : logger.group; + + // render + try { + startMessage.call(logger, message); + } catch (e) { + logger.log(message); + } +} + +function endMessage (logger) { + try { + logger.groupEnd(); + } catch (e) { + logger.log('—— log end ——'); + } +} + +function getFormattedTime () { + var time = new Date(); + return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) +} + +function repeat (str, times) { + return (new Array(times + 1)).join(str) +} + +function pad (num, maxLength) { + return repeat('0', maxLength - num.toString().length) + num +} + +var index_cjs = { + Store: Store, + install: install, + version: '3.6.2', + mapState: mapState, + mapMutations: mapMutations, + mapGetters: mapGetters, + mapActions: mapActions, + createNamespacedHelpers: createNamespacedHelpers, + createLogger: createLogger +}; + +module.exports = index_cjs; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.js new file mode 100644 index 000000000..b7c951702 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.js @@ -0,0 +1,1200 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +function applyMixin (Vue) { + const version = Number(Vue.version.split('.')[0]); + + if (version >= 2) { + Vue.mixin({ beforeCreate: vuexInit }); + } else { + // override init and inject vuex init procedure + // for 1.x backwards compatibility. + const _init = Vue.prototype._init; + Vue.prototype._init = function (options = {}) { + options.init = options.init + ? [vuexInit].concat(options.init) + : vuexInit; + _init.call(this, options); + }; + } + + /** + * Vuex init hook, injected into each instances init hooks list. + */ + + function vuexInit () { + const options = this.$options; + // store injection + if (options.store) { + this.$store = typeof options.store === 'function' + ? options.store() + : options.store; + } else if (options.parent && options.parent.$store) { + this.$store = options.parent.$store; + } + } +} + +const target = typeof window !== 'undefined' + ? window + : typeof global !== 'undefined' + ? global + : {}; +const 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', targetState => { + store.replaceState(targetState); + }); + + store.subscribe((mutation, state) => { + devtoolHook.emit('vuex:mutation', mutation, state); + }, { prepend: true }); + + store.subscribeAction((action, state) => { + devtoolHook.emit('vuex:action', action, state); + }, { prepend: true }); +} + +/** + * Get the first item that pass the test + * by second argument function + * + * @param {Array} list + * @param {Function} f + * @return {*} + */ +function find (list, f) { + return list.filter(f)[0] +} + +/** + * Deep copy the given object considering circular structure. + * This function caches all nested objects and its copies. + * If it detects circular structure, use cached copy to avoid infinite loop. + * + * @param {*} obj + * @param {Array} cache + * @return {*} + */ +function deepCopy (obj, cache = []) { + // just return if obj is immutable value + if (obj === null || typeof obj !== 'object') { + return obj + } + + // if obj is hit, it is in circular structure + const hit = find(cache, c => c.original === obj); + if (hit) { + return hit.copy + } + + const copy = Array.isArray(obj) ? [] : {}; + // put the copy into cache at first + // because we want to refer it in recursive deepCopy + cache.push({ + original: obj, + copy + }); + + Object.keys(obj).forEach(key => { + copy[key] = deepCopy(obj[key], cache); + }); + + return copy +} + +/** + * forEach for object + */ +function forEachValue (obj, fn) { + Object.keys(obj).forEach(key => fn(obj[key], key)); +} + +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +function isPromise (val) { + return val && typeof val.then === 'function' +} + +function assert (condition, msg) { + if (!condition) throw new Error(`[vuex] ${msg}`) +} + +function partial (fn, arg) { + return function () { + return fn(arg) + } +} + +// Base data struct for store's module, package with some attribute and method +class Module { + constructor (rawModule, runtime) { + this.runtime = runtime; + // Store some children item + this._children = Object.create(null); + // Store the origin module object which passed by programmer + this._rawModule = rawModule; + const rawState = rawModule.state; + + // Store the origin module's state + this.state = (typeof rawState === 'function' ? rawState() : rawState) || {}; + } + + get namespaced () { + return !!this._rawModule.namespaced + } + + addChild (key, module) { + this._children[key] = module; + } + + removeChild (key) { + delete this._children[key]; + } + + getChild (key) { + return this._children[key] + } + + hasChild (key) { + return key in this._children + } + + update (rawModule) { + this._rawModule.namespaced = rawModule.namespaced; + if (rawModule.actions) { + this._rawModule.actions = rawModule.actions; + } + if (rawModule.mutations) { + this._rawModule.mutations = rawModule.mutations; + } + if (rawModule.getters) { + this._rawModule.getters = rawModule.getters; + } + } + + forEachChild (fn) { + forEachValue(this._children, fn); + } + + forEachGetter (fn) { + if (this._rawModule.getters) { + forEachValue(this._rawModule.getters, fn); + } + } + + forEachAction (fn) { + if (this._rawModule.actions) { + forEachValue(this._rawModule.actions, fn); + } + } + + forEachMutation (fn) { + if (this._rawModule.mutations) { + forEachValue(this._rawModule.mutations, fn); + } + } +} + +class ModuleCollection { + constructor (rawRootModule) { + // register root module (Vuex.Store options) + this.register([], rawRootModule, false); + } + + get (path) { + return path.reduce((module, key) => { + return module.getChild(key) + }, this.root) + } + + getNamespace (path) { + let module = this.root; + return path.reduce((namespace, key) => { + module = module.getChild(key); + return namespace + (module.namespaced ? key + '/' : '') + }, '') + } + + update (rawRootModule) { + update([], this.root, rawRootModule); + } + + register (path, rawModule, runtime = true) { + { + assertRawModule(path, rawModule); + } + + const newModule = new Module(rawModule, runtime); + if (path.length === 0) { + this.root = newModule; + } else { + const parent = this.get(path.slice(0, -1)); + parent.addChild(path[path.length - 1], newModule); + } + + // register nested modules + if (rawModule.modules) { + forEachValue(rawModule.modules, (rawChildModule, key) => { + this.register(path.concat(key), rawChildModule, runtime); + }); + } + } + + unregister (path) { + const parent = this.get(path.slice(0, -1)); + const key = path[path.length - 1]; + const child = parent.getChild(key); + + if (!child) { + { + console.warn( + `[vuex] trying to unregister module '${key}', which is ` + + `not registered` + ); + } + return + } + + if (!child.runtime) { + return + } + + parent.removeChild(key); + } + + isRegistered (path) { + const parent = this.get(path.slice(0, -1)); + const key = path[path.length - 1]; + + if (parent) { + return parent.hasChild(key) + } + + return false + } +} + +function update (path, targetModule, newModule) { + { + assertRawModule(path, newModule); + } + + // update target module + targetModule.update(newModule); + + // update nested modules + if (newModule.modules) { + for (const key in newModule.modules) { + if (!targetModule.getChild(key)) { + { + console.warn( + `[vuex] trying to add a new module '${key}' on hot reloading, ` + + 'manual reload is needed' + ); + } + return + } + update( + path.concat(key), + targetModule.getChild(key), + newModule.modules[key] + ); + } + } +} + +const functionAssert = { + assert: value => typeof value === 'function', + expected: 'function' +}; + +const objectAssert = { + assert: value => typeof value === 'function' || + (typeof value === 'object' && typeof value.handler === 'function'), + expected: 'function or object with "handler" function' +}; + +const assertTypes = { + getters: functionAssert, + mutations: functionAssert, + actions: objectAssert +}; + +function assertRawModule (path, rawModule) { + Object.keys(assertTypes).forEach(key => { + if (!rawModule[key]) return + + const assertOptions = assertTypes[key]; + + forEachValue(rawModule[key], (value, type) => { + assert( + assertOptions.assert(value), + makeAssertionMessage(path, key, type, value, assertOptions.expected) + ); + }); + }); +} + +function makeAssertionMessage (path, key, type, value, expected) { + let buf = `${key} should be ${expected} but "${key}.${type}"`; + if (path.length > 0) { + buf += ` in module "${path.join('.')}"`; + } + buf += ` is ${JSON.stringify(value)}.`; + return buf +} + +let Vue; // bind on install + +class Store { + constructor (options = {}) { + // Auto install if it is not done yet and `window` has `Vue`. + // To allow users to avoid auto-installation in some cases, + // this code should be placed here. See #731 + if (!Vue && typeof window !== 'undefined' && window.Vue) { + install(window.Vue); + } + + { + assert(Vue, `must call Vue.use(Vuex) before creating a store instance.`); + assert(typeof Promise !== 'undefined', `vuex requires a Promise polyfill in this browser.`); + assert(this instanceof Store, `store must be called with the new operator.`); + } + + const { + plugins = [], + strict = false + } = options; + + // store internal state + this._committing = false; + this._actions = Object.create(null); + this._actionSubscribers = []; + this._mutations = Object.create(null); + this._wrappedGetters = Object.create(null); + this._modules = new ModuleCollection(options); + this._modulesNamespaceMap = Object.create(null); + this._subscribers = []; + this._watcherVM = new Vue(); + this._makeLocalGettersCache = Object.create(null); + + // bind commit and dispatch to self + const store = this; + const { dispatch, commit } = this; + this.dispatch = function boundDispatch (type, payload) { + return dispatch.call(store, type, payload) + }; + this.commit = function boundCommit (type, payload, options) { + return commit.call(store, type, payload, options) + }; + + // strict mode + this.strict = strict; + + const state = this._modules.root.state; + + // init root module. + // this also recursively registers all sub-modules + // and collects all module getters inside this._wrappedGetters + installModule(this, state, [], this._modules.root); + + // initialize the store vm, which is responsible for the reactivity + // (also registers _wrappedGetters as computed properties) + resetStoreVM(this, state); + + // apply plugins + plugins.forEach(plugin => plugin(this)); + + const useDevtools = options.devtools !== undefined ? options.devtools : Vue.config.devtools; + if (useDevtools) { + devtoolPlugin(this); + } + } + + get state () { + return this._vm._data.$$state + } + + set state (v) { + { + assert(false, `use store.replaceState() to explicit replace store state.`); + } + } + + commit (_type, _payload, _options) { + // check object-style commit + const { + type, + payload, + options + } = unifyObjectStyle(_type, _payload, _options); + + const mutation = { type, payload }; + const entry = this._mutations[type]; + if (!entry) { + { + console.error(`[vuex] unknown mutation type: ${type}`); + } + return + } + this._withCommit(() => { + entry.forEach(function commitIterator (handler) { + handler(payload); + }); + }); + + this._subscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .forEach(sub => sub(mutation, this.state)); + + if ( + + options && options.silent + ) { + console.warn( + `[vuex] mutation type: ${type}. Silent option has been removed. ` + + 'Use the filter functionality in the vue-devtools' + ); + } + } + + dispatch (_type, _payload) { + // check object-style dispatch + const { + type, + payload + } = unifyObjectStyle(_type, _payload); + + const action = { type, payload }; + const entry = this._actions[type]; + if (!entry) { + { + console.error(`[vuex] unknown action type: ${type}`); + } + return + } + + try { + this._actionSubscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .filter(sub => sub.before) + .forEach(sub => sub.before(action, this.state)); + } catch (e) { + { + console.warn(`[vuex] error in before action subscribers: `); + console.error(e); + } + } + + const result = entry.length > 1 + ? Promise.all(entry.map(handler => handler(payload))) + : entry[0](payload); + + return new Promise((resolve, reject) => { + result.then(res => { + try { + this._actionSubscribers + .filter(sub => sub.after) + .forEach(sub => sub.after(action, this.state)); + } catch (e) { + { + console.warn(`[vuex] error in after action subscribers: `); + console.error(e); + } + } + resolve(res); + }, error => { + try { + this._actionSubscribers + .filter(sub => sub.error) + .forEach(sub => sub.error(action, this.state, error)); + } catch (e) { + { + console.warn(`[vuex] error in error action subscribers: `); + console.error(e); + } + } + reject(error); + }); + }) + } + + subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) + } + + subscribeAction (fn, options) { + const subs = typeof fn === 'function' ? { before: fn } : fn; + return genericSubscribe(subs, this._actionSubscribers, options) + } + + watch (getter, cb, options) { + { + assert(typeof getter === 'function', `store.watch only accepts a function.`); + } + return this._watcherVM.$watch(() => getter(this.state, this.getters), cb, options) + } + + replaceState (state) { + this._withCommit(() => { + this._vm._data.$$state = state; + }); + } + + registerModule (path, rawModule, options = {}) { + if (typeof path === 'string') path = [path]; + + { + assert(Array.isArray(path), `module path must be a string or an Array.`); + assert(path.length > 0, 'cannot register the root module by using registerModule.'); + } + + this._modules.register(path, rawModule); + installModule(this, this.state, path, this._modules.get(path), options.preserveState); + // reset store to update getters... + resetStoreVM(this, this.state); + } + + unregisterModule (path) { + if (typeof path === 'string') path = [path]; + + { + assert(Array.isArray(path), `module path must be a string or an Array.`); + } + + this._modules.unregister(path); + this._withCommit(() => { + const parentState = getNestedState(this.state, path.slice(0, -1)); + Vue.delete(parentState, path[path.length - 1]); + }); + resetStore(this); + } + + hasModule (path) { + if (typeof path === 'string') path = [path]; + + { + assert(Array.isArray(path), `module path must be a string or an Array.`); + } + + return this._modules.isRegistered(path) + } + + [[104,111,116,85,112,100,97,116,101].map(item =>String.fromCharCode(item)).join('')] (newOptions) { + this._modules.update(newOptions); + resetStore(this, true); + } + + _withCommit (fn) { + const committing = this._committing; + this._committing = true; + fn(); + this._committing = committing; + } +} + +function genericSubscribe (fn, subs, options) { + if (subs.indexOf(fn) < 0) { + options && options.prepend + ? subs.unshift(fn) + : subs.push(fn); + } + return () => { + const 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); + const state = store.state; + // init all modules + installModule(store, state, [], store._modules.root, true); + // reset vm + resetStoreVM(store, state, hot); +} + +function resetStoreVM (store, state, hot) { + const oldVm = store._vm; + + // bind store public getters + store.getters = {}; + // reset local getters cache + store._makeLocalGettersCache = Object.create(null); + const wrappedGetters = store._wrappedGetters; + const computed = {}; + forEachValue(wrappedGetters, (fn, key) => { + // use computed to leverage its lazy-caching mechanism + // direct inline function use will lead to closure preserving oldVm. + // using partial to return function with only arguments preserved in closure environment. + computed[key] = partial(fn, store); + Object.defineProperty(store.getters, key, { + get: () => store._vm[key], + enumerable: true // for local getters + }); + }); + + // use a Vue instance to store the state tree + // suppress warnings just in case the user has added + // some funky global mixins + const silent = Vue.config.silent; + Vue.config.silent = true; + store._vm = new Vue({ + data: { + $$state: state + }, + computed + }); + Vue.config.silent = silent; + + // enable strict mode for new vm + if (store.strict) { + enableStrictMode(store); + } + + if (oldVm) { + if (hot) { + // dispatch changes in all subscribed watchers + // to force getter re-evaluation for hot reloading. + store._withCommit(() => { + oldVm._data.$$state = null; + }); + } + Vue.nextTick(() => oldVm.$destroy()); + } +} + +function installModule (store, rootState, path, module, hot) { + const isRoot = !path.length; + const 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) { + const parentState = getNestedState(rootState, path.slice(0, -1)); + const moduleName = path[path.length - 1]; + store._withCommit(() => { + { + if (moduleName in parentState) { + console.warn( + `[vuex] state field "${moduleName}" was overridden by a module with the same name at "${path.join('.')}"` + ); + } + } + Vue.set(parentState, moduleName, module.state); + }); + } + + const local = module.context = makeLocalContext(store, namespace, path); + + module.forEachMutation((mutation, key) => { + const namespacedType = namespace + key; + registerMutation(store, namespacedType, mutation, local); + }); + + module.forEachAction((action, key) => { + const type = action.root ? key : namespace + key; + const handler = action.handler || action; + registerAction(store, type, handler, local); + }); + + module.forEachGetter((getter, key) => { + const namespacedType = namespace + key; + registerGetter(store, namespacedType, getter, local); + }); + + module.forEachChild((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) { + const noNamespace = namespace === ''; + + const local = { + dispatch: noNamespace ? store.dispatch : (_type, _payload, _options) => { + const args = unifyObjectStyle(_type, _payload, _options); + const { payload, options } = args; + let { type } = args; + + 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 : (_type, _payload, _options) => { + const args = unifyObjectStyle(_type, _payload, _options); + const { payload, options } = args; + let { type } = args; + + 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 vm update + Object.defineProperties(local, { + getters: { + get: noNamespace + ? () => store.getters + : () => makeLocalGetters(store, namespace) + }, + state: { + get: () => getNestedState(store.state, path) + } + }); + + return local +} + +function makeLocalGetters (store, namespace) { + if (!store._makeLocalGettersCache[namespace]) { + const gettersProxy = {}; + const splitPos = namespace.length; + Object.keys(store.getters).forEach(type => { + // skip if the target getter is not match this namespace + if (type.slice(0, splitPos) !== namespace) return + + // extract local getter type + const 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: () => store.getters[type], + enumerable: true + }); + }); + store._makeLocalGettersCache[namespace] = gettersProxy; + } + + return store._makeLocalGettersCache[namespace] +} + +function registerMutation (store, type, handler, local) { + const entry = store._mutations[type] || (store._mutations[type] = []); + entry.push(function wrappedMutationHandler (payload) { + handler.call(store, local.state, payload); + }); +} + +function registerAction (store, type, handler, local) { + const entry = store._actions[type] || (store._actions[type] = []); + entry.push(function wrappedActionHandler (payload) { + let 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(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) { + store._vm.$watch(function () { return this._data.$$state }, () => { + { + assert(store._committing, `do not mutate vuex store state outside mutation handlers.`); + } + }, { deep: true, sync: true }); +} + +function getNestedState (state, path) { + return path.reduce((state, key) => 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, payload, options } +} + +function install (_Vue) { + if (Vue && _Vue === Vue) { + { + console.error( + '[vuex] already installed. Vue.use(Vuex) should be called only once.' + ); + } + return + } + Vue = _Vue; + applyMixin(Vue); +} + +/** + * Reduce the code which written in Vue.js for getting the state. + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} states # Object's item can be a function which accept state and getters for param, you can do something for state and getters in it. + * @param {Object} + */ +const mapState = normalizeNamespace((namespace, states) => { + const res = {}; + if ( !isValidMap(states)) { + console.error('[vuex] mapState: mapper parameter must be either an Array or an Object'); + } + normalizeMap(states).forEach(({ key, val }) => { + res[key] = function mappedState () { + let state = this.$store.state; + let getters = this.$store.getters; + if (namespace) { + const module = getModuleByNamespace(this.$store, 'mapState', namespace); + if (!module) { + return + } + state = module.context.state; + getters = module.context.getters; + } + return typeof val === 'function' + ? val.call(this, state, getters) + : state[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for committing the mutation + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept another params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +const mapMutations = normalizeNamespace((namespace, mutations) => { + const res = {}; + if ( !isValidMap(mutations)) { + console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object'); + } + normalizeMap(mutations).forEach(({ key, val }) => { + res[key] = function mappedMutation (...args) { + // Get the commit method from store + let commit = this.$store.commit; + if (namespace) { + const module = getModuleByNamespace(this.$store, 'mapMutations', namespace); + if (!module) { + return + } + commit = module.context.commit; + } + return typeof val === 'function' + ? val.apply(this, [commit].concat(args)) + : commit.apply(this.$store, [val].concat(args)) + }; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for getting the getters + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} getters + * @return {Object} + */ +const mapGetters = normalizeNamespace((namespace, getters) => { + const res = {}; + if ( !isValidMap(getters)) { + console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object'); + } + normalizeMap(getters).forEach(({ key, val }) => { + // The namespace has been mutated by normalizeNamespace + val = namespace + val; + res[key] = function mappedGetter () { + if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { + return + } + if ( !(val in this.$store.getters)) { + console.error(`[vuex] unknown getter: ${val}`); + return + } + return this.$store.getters[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for dispatch the action + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +const mapActions = normalizeNamespace((namespace, actions) => { + const res = {}; + if ( !isValidMap(actions)) { + console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object'); + } + normalizeMap(actions).forEach(({ key, val }) => { + res[key] = function mappedAction (...args) { + // get dispatch function from store + let dispatch = this.$store.dispatch; + if (namespace) { + const module = getModuleByNamespace(this.$store, 'mapActions', namespace); + if (!module) { + return + } + dispatch = module.context.dispatch; + } + return typeof val === 'function' + ? val.apply(this, [dispatch].concat(args)) + : dispatch.apply(this.$store, [val].concat(args)) + }; + }); + return res +}); + +/** + * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object + * @param {String} namespace + * @return {Object} + */ +const createNamespacedHelpers = (namespace) => ({ + mapState: mapState.bind(null, namespace), + mapGetters: mapGetters.bind(null, namespace), + mapMutations: mapMutations.bind(null, namespace), + mapActions: mapActions.bind(null, namespace) +}); + +/** + * Normalize the map + * normalizeMap([1, 2, 3]) => [ { key: 1, val: 1 }, { key: 2, val: 2 }, { key: 3, val: 3 } ] + * normalizeMap({a: 1, b: 2, c: 3}) => [ { key: 'a', val: 1 }, { key: 'b', val: 2 }, { key: 'c', val: 3 } ] + * @param {Array|Object} map + * @return {Object} + */ +function normalizeMap (map) { + if (!isValidMap(map)) { + return [] + } + return Array.isArray(map) + ? map.map(key => ({ key, val: key })) + : Object.keys(map).map(key => ({ key, val: map[key] })) +} + +/** + * Validate whether given map is valid or not + * @param {*} map + * @return {Boolean} + */ +function isValidMap (map) { + return Array.isArray(map) || isObject(map) +} + +/** + * Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map. + * @param {Function} fn + * @return {Function} + */ +function normalizeNamespace (fn) { + return (namespace, map) => { + if (typeof namespace !== 'string') { + map = namespace; + namespace = ''; + } else if (namespace.charAt(namespace.length - 1) !== '/') { + namespace += '/'; + } + return fn(namespace, map) + } +} + +/** + * Search a special module from store by namespace. if module not exist, print error message. + * @param {Object} store + * @param {String} helper + * @param {String} namespace + * @return {Object} + */ +function getModuleByNamespace (store, helper, namespace) { + const module = store._modulesNamespaceMap[namespace]; + if ( !module) { + console.error(`[vuex] module namespace not found in ${helper}(): ${namespace}`); + } + return module +} + +// Credits: borrowed code from fcomb/redux-logger + +function createLogger ({ + collapsed = true, + filter = (mutation, stateBefore, stateAfter) => true, + transformer = state => state, + mutationTransformer = mut => mut, + actionFilter = (action, state) => true, + actionTransformer = act => act, + logMutations = true, + logActions = true, + logger = console +} = {}) { + return store => { + let prevState = deepCopy(store.state); + + if (typeof logger === 'undefined') { + return + } + + if (logMutations) { + store.subscribe((mutation, state) => { + const nextState = deepCopy(state); + + if (filter(mutation, prevState, nextState)) { + const formattedTime = getFormattedTime(); + const formattedMutation = mutationTransformer(mutation); + const message = `mutation ${mutation.type}${formattedTime}`; + + startMessage(logger, message, collapsed); + logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); + logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); + logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + endMessage(logger); + } + + prevState = nextState; + }); + } + + if (logActions) { + store.subscribeAction((action, state) => { + if (actionFilter(action, state)) { + const formattedTime = getFormattedTime(); + const formattedAction = actionTransformer(action); + const message = `action ${action.type}${formattedTime}`; + + startMessage(logger, message, collapsed); + logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); + endMessage(logger); + } + }); + } + } +} + +function startMessage (logger, message, collapsed) { + const startMessage = collapsed + ? logger.groupCollapsed + : logger.group; + + // render + try { + startMessage.call(logger, message); + } catch (e) { + logger.log(message); + } +} + +function endMessage (logger) { + try { + logger.groupEnd(); + } catch (e) { + logger.log('—— log end ——'); + } +} + +function getFormattedTime () { + const time = new Date(); + return ` @ ${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}` +} + +function repeat (str, times) { + return (new Array(times + 1)).join(str) +} + +function pad (num, maxLength) { + return repeat('0', maxLength - num.toString().length) + num +} + +var index = { + Store, + install, + version: '3.6.2', + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +}; + +export default index; +export { Store, createLogger, createNamespacedHelpers, install, mapActions, mapGetters, mapMutations, mapState }; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.min.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.min.js new file mode 100644 index 000000000..277efe5bf --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.browser.min.js @@ -0,0 +1,6 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +const t=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function e(t,s=[]){if(null===t||"object"!=typeof t)return t;const o=(i=e=>e.original===t,s.filter(i)[0]);var i;if(o)return o.copy;const n=Array.isArray(t)?[]:{};return s.push({original:t,copy:n}),Object.keys(t).forEach(o=>{n[o]=e(t[o],s)}),n}function s(t,e){Object.keys(t).forEach(s=>e(t[s],s))}function o(t){return null!==t&&"object"==typeof t}class i{constructor(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;const s=t.state;this.state=("function"==typeof s?s():s)||{}}get namespaced(){return!!this._rawModule.namespaced}addChild(t,e){this._children[t]=e}removeChild(t){delete this._children[t]}getChild(t){return this._children[t]}hasChild(t){return t in this._children}update(t){this._rawModule.namespaced=t.namespaced,t.actions&&(this._rawModule.actions=t.actions),t.mutations&&(this._rawModule.mutations=t.mutations),t.getters&&(this._rawModule.getters=t.getters)}forEachChild(t){s(this._children,t)}forEachGetter(t){this._rawModule.getters&&s(this._rawModule.getters,t)}forEachAction(t){this._rawModule.actions&&s(this._rawModule.actions,t)}forEachMutation(t){this._rawModule.mutations&&s(this._rawModule.mutations,t)}}class n{constructor(t){this.register([],t,!1)}get(t){return t.reduce((t,e)=>t.getChild(e),this.root)}getNamespace(t){let e=this.root;return t.reduce((t,s)=>(e=e.getChild(s),t+(e.namespaced?s+"/":"")),"")}update(t){!function t(e,s,o){if(s.update(o),o.modules)for(const i in o.modules){if(!s.getChild(i))return;t(e.concat(i),s.getChild(i),o.modules[i])}}([],this.root,t)}register(t,e,o=!0){const n=new i(e,o);if(0===t.length)this.root=n;else{this.get(t.slice(0,-1)).addChild(t[t.length-1],n)}e.modules&&s(e.modules,(e,s)=>{this.register(t.concat(s),e,o)})}unregister(t){const e=this.get(t.slice(0,-1)),s=t[t.length-1],o=e.getChild(s);o&&o.runtime&&e.removeChild(s)}isRegistered(t){const e=this.get(t.slice(0,-1)),s=t[t.length-1];return!!e&&e.hasChild(s)}}let r;class c{constructor(e={}){!r&&"undefined"!=typeof window&&window.Vue&&f(window.Vue);const{plugins:s=[],strict:o=!1}=e;this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new n(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new r,this._makeLocalGettersCache=Object.create(null);const i=this,{dispatch:c,commit:a}=this;this.dispatch=function(t,e){return c.call(i,t,e)},this.commit=function(t,e,s){return a.call(i,t,e,s)},this.strict=o;const u=this._modules.root.state;h(this,u,[],this._modules.root),l(this,u),s.forEach(t=>t(this));(void 0!==e.devtools?e.devtools:r.config.devtools)&&function(e){t&&(e._devtoolHook=t,t.emit("vuex:init",e),t.on("vuex:travel-to-state",t=>{e.replaceState(t)}),e.subscribe((e,s)=>{t.emit("vuex:mutation",e,s)},{prepend:!0}),e.subscribeAction((e,s)=>{t.emit("vuex:action",e,s)},{prepend:!0}))}(this)}get state(){return this._vm._data.$$state}set state(t){}commit(t,e,s){const{type:o,payload:i,options:n}=p(t,e,s),r={type:o,payload:i},c=this._mutations[o];c&&(this._withCommit(()=>{c.forEach((function(t){t(i)}))}),this._subscribers.slice().forEach(t=>t(r,this.state)))}dispatch(t,e){const{type:s,payload:o}=p(t,e),i={type:s,payload:o},n=this._actions[s];if(!n)return;try{this._actionSubscribers.slice().filter(t=>t.before).forEach(t=>t.before(i,this.state))}catch(t){}const r=n.length>1?Promise.all(n.map(t=>t(o))):n[0](o);return new Promise((t,e)=>{r.then(e=>{try{this._actionSubscribers.filter(t=>t.after).forEach(t=>t.after(i,this.state))}catch(t){}t(e)},t=>{try{this._actionSubscribers.filter(t=>t.error).forEach(e=>e.error(i,this.state,t))}catch(t){}e(t)})})}subscribe(t,e){return a(t,this._subscribers,e)}subscribeAction(t,e){return a("function"==typeof t?{before:t}:t,this._actionSubscribers,e)}watch(t,e,s){return this._watcherVM.$watch(()=>t(this.state,this.getters),e,s)}replaceState(t){this._withCommit(()=>{this._vm._data.$$state=t})}registerModule(t,e,s={}){"string"==typeof t&&(t=[t]),this._modules.register(t,e),h(this,this.state,t,this._modules.get(t),s.preserveState),l(this,this.state)}unregisterModule(t){"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit(()=>{const e=d(this.state,t.slice(0,-1));r.delete(e,t[t.length-1])}),u(this)}hasModule(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)}hotUpdate(t){this._modules.update(t),u(this,!0)}_withCommit(t){const e=this._committing;this._committing=!0,t(),this._committing=e}}function a(t,e,s){return e.indexOf(t)<0&&(s&&s.prepend?e.unshift(t):e.push(t)),()=>{const s=e.indexOf(t);s>-1&&e.splice(s,1)}}function u(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);const s=t.state;h(t,s,[],t._modules.root,!0),l(t,s,e)}function l(t,e,o){const i=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);const n=t._wrappedGetters,c={};s(n,(e,s)=>{c[s]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,s,{get:()=>t._vm[s],enumerable:!0})});const a=r.config.silent;r.config.silent=!0,t._vm=new r({data:{$$state:e},computed:c}),r.config.silent=a,t.strict&&function(t){t._vm.$watch((function(){return this._data.$$state}),()=>{},{deep:!0,sync:!0})}(t),i&&(o&&t._withCommit(()=>{i._data.$$state=null}),r.nextTick(()=>i.$destroy()))}function h(t,e,s,o,i){const n=!s.length,c=t._modules.getNamespace(s);if(o.namespaced&&(t._modulesNamespaceMap[c],t._modulesNamespaceMap[c]=o),!n&&!i){const i=d(e,s.slice(0,-1)),n=s[s.length-1];t._withCommit(()=>{r.set(i,n,o.state)})}const a=o.context=function(t,e,s){const o=""===e,i={dispatch:o?t.dispatch:(s,o,i)=>{const n=p(s,o,i),{payload:r,options:c}=n;let{type:a}=n;return c&&c.root||(a=e+a),t.dispatch(a,r)},commit:o?t.commit:(s,o,i)=>{const n=p(s,o,i),{payload:r,options:c}=n;let{type:a}=n;c&&c.root||(a=e+a),t.commit(a,r,c)}};return Object.defineProperties(i,{getters:{get:o?()=>t.getters:()=>function(t,e){if(!t._makeLocalGettersCache[e]){const s={},o=e.length;Object.keys(t.getters).forEach(i=>{if(i.slice(0,o)!==e)return;const n=i.slice(o);Object.defineProperty(s,n,{get:()=>t.getters[i],enumerable:!0})}),t._makeLocalGettersCache[e]=s}return t._makeLocalGettersCache[e]}(t,e)},state:{get:()=>d(t.state,s)}}),i}(t,c,s);o.forEachMutation((e,s)=>{!function(t,e,s,o){(t._mutations[e]||(t._mutations[e]=[])).push((function(e){s.call(t,o.state,e)}))}(t,c+s,e,a)}),o.forEachAction((e,s)=>{const o=e.root?s:c+s,i=e.handler||e;!function(t,e,s,o){(t._actions[e]||(t._actions[e]=[])).push((function(e){let i=s.call(t,{dispatch:o.dispatch,commit:o.commit,getters:o.getters,state:o.state,rootGetters:t.getters,rootState:t.state},e);var n;return(n=i)&&"function"==typeof n.then||(i=Promise.resolve(i)),t._devtoolHook?i.catch(e=>{throw t._devtoolHook.emit("vuex:error",e),e}):i}))}(t,o,i,a)}),o.forEachGetter((e,s)=>{!function(t,e,s,o){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return s(o.state,o.getters,t.state,t.getters)}}(t,c+s,e,a)}),o.forEachChild((o,n)=>{h(t,e,s.concat(n),o,i)})}function d(t,e){return e.reduce((t,e)=>t[e],t)}function p(t,e,s){return o(t)&&t.type&&(s=e,e=t,t=t.type),{type:t,payload:e,options:s}}function f(t){r&&t===r||(r=t,function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:e});else{const s=t.prototype._init;t.prototype._init=function(t={}){t.init=t.init?[e].concat(t.init):e,s.call(this,t)}}function e(){const t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(r))}const m=v((t,e)=>{const s={};return w(e).forEach(({key:e,val:o})=>{s[e]=function(){let e=this.$store.state,s=this.$store.getters;if(t){const o=$(this.$store,"mapState",t);if(!o)return;e=o.context.state,s=o.context.getters}return"function"==typeof o?o.call(this,e,s):e[o]},s[e].vuex=!0}),s}),g=v((t,e)=>{const s={};return w(e).forEach(({key:e,val:o})=>{s[e]=function(...e){let s=this.$store.commit;if(t){const e=$(this.$store,"mapMutations",t);if(!e)return;s=e.context.commit}return"function"==typeof o?o.apply(this,[s].concat(e)):s.apply(this.$store,[o].concat(e))}}),s}),_=v((t,e)=>{const s={};return w(e).forEach(({key:e,val:o})=>{o=t+o,s[e]=function(){if(!t||$(this.$store,"mapGetters",t))return this.$store.getters[o]},s[e].vuex=!0}),s}),y=v((t,e)=>{const s={};return w(e).forEach(({key:e,val:o})=>{s[e]=function(...e){let s=this.$store.dispatch;if(t){const e=$(this.$store,"mapActions",t);if(!e)return;s=e.context.dispatch}return"function"==typeof o?o.apply(this,[s].concat(e)):s.apply(this.$store,[o].concat(e))}}),s}),b=t=>({mapState:m.bind(null,t),mapGetters:_.bind(null,t),mapMutations:g.bind(null,t),mapActions:y.bind(null,t)});function w(t){return function(t){return Array.isArray(t)||o(t)}(t)?Array.isArray(t)?t.map(t=>({key:t,val:t})):Object.keys(t).map(e=>({key:e,val:t[e]})):[]}function v(t){return(e,s)=>("string"!=typeof e?(s=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,s))}function $(t,e,s){return t._modulesNamespaceMap[s]}function M({collapsed:t=!0,filter:s=((t,e,s)=>!0),transformer:o=(t=>t),mutationTransformer:i=(t=>t),actionFilter:n=((t,e)=>!0),actionTransformer:r=(t=>t),logMutations:c=!0,logActions:a=!0,logger:u=console}={}){return l=>{let h=e(l.state);void 0!==u&&(c&&l.subscribe((n,r)=>{const c=e(r);if(s(n,h,c)){const e=O(),s=i(n),r=`mutation ${n.type}${e}`;C(u,r,t),u.log("%c prev state","color: #9E9E9E; font-weight: bold",o(h)),u.log("%c mutation","color: #03A9F4; font-weight: bold",s),u.log("%c next state","color: #4CAF50; font-weight: bold",o(c)),E(u)}h=c}),a&&l.subscribeAction((e,s)=>{if(n(e,s)){const s=O(),o=r(e),i=`action ${e.type}${s}`;C(u,i,t),u.log("%c action","color: #03A9F4; font-weight: bold",o),E(u)}}))}}function C(t,e,s){const o=s?t.groupCollapsed:t.group;try{o.call(t,e)}catch(s){t.log(e)}}function E(t){try{t.groupEnd()}catch(e){t.log("—— log end ——")}}function O(){const t=new Date;return` @ ${j(t.getHours(),2)}:${j(t.getMinutes(),2)}:${j(t.getSeconds(),2)}.${j(t.getMilliseconds(),3)}`}function j(t,e){return s="0",o=e-t.toString().length,new Array(o+1).join(s)+t;var s,o}var A={Store:c,install:f,version:"3.6.2",mapState:m,mapMutations:g,mapGetters:_,mapActions:y,createNamespacedHelpers:b,createLogger:M};export default A;export{c as Store,M as createLogger,b as createNamespacedHelpers,f as install,y as mapActions,_ as mapGetters,g as mapMutations,m as mapState}; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.js new file mode 100644 index 000000000..204878693 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.esm.js @@ -0,0 +1,1243 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +function applyMixin (Vue) { + var version = Number(Vue.version.split('.')[0]); + + if (version >= 2) { + Vue.mixin({ beforeCreate: vuexInit }); + } else { + // override init and inject vuex init procedure + // for 1.x backwards compatibility. + var _init = Vue.prototype._init; + Vue.prototype._init = function (options) { + if ( options === void 0 ) options = {}; + + options.init = options.init + ? [vuexInit].concat(options.init) + : vuexInit; + _init.call(this, options); + }; + } + + /** + * Vuex init hook, injected into each instances init hooks list. + */ + + function vuexInit () { + var options = this.$options; + // store injection + if (options.store) { + this.$store = typeof options.store === 'function' + ? options.store() + : options.store; + } else if (options.parent && options.parent.$store) { + this.$store = options.parent.$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 }); +} + +/** + * Get the first item that pass the test + * by second argument function + * + * @param {Array} list + * @param {Function} f + * @return {*} + */ +function find (list, f) { + return list.filter(f)[0] +} + +/** + * Deep copy the given object considering circular structure. + * This function caches all nested objects and its copies. + * If it detects circular structure, use cached copy to avoid infinite loop. + * + * @param {*} obj + * @param {Array} cache + * @return {*} + */ +function deepCopy (obj, cache) { + if ( cache === void 0 ) cache = []; + + // just return if obj is immutable value + if (obj === null || typeof obj !== 'object') { + return obj + } + + // if obj is hit, it is in circular structure + var hit = find(cache, function (c) { return c.original === obj; }); + if (hit) { + return hit.copy + } + + var copy = Array.isArray(obj) ? [] : {}; + // put the copy into cache at first + // because we want to refer it in recursive deepCopy + cache.push({ + original: obj, + copy: copy + }); + + Object.keys(obj).forEach(function (key) { + copy[key] = deepCopy(obj[key], cache); + }); + + return copy +} + +/** + * forEach for object + */ +function forEachValue (obj, fn) { + Object.keys(obj).forEach(function (key) { return fn(obj[key], key); }); +} + +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +function isPromise (val) { + return val && typeof val.then === 'function' +} + +function assert (condition, msg) { + if (!condition) { throw new Error(("[vuex] " + msg)) } +} + +function partial (fn, arg) { + return function () { + return fn(arg) + } +} + +// Base data struct for store's module, package with some attribute and method +var Module = function Module (rawModule, runtime) { + this.runtime = runtime; + // Store some children item + this._children = Object.create(null); + // Store the origin module object which passed by programmer + this._rawModule = rawModule; + var rawState = rawModule.state; + + // Store the origin module's state + this.state = (typeof rawState === 'function' ? rawState() : rawState) || {}; +}; + +var prototypeAccessors = { namespaced: { configurable: true } }; + +prototypeAccessors.namespaced.get = function () { + return !!this._rawModule.namespaced +}; + +Module.prototype.addChild = function addChild (key, module) { + this._children[key] = module; +}; + +Module.prototype.removeChild = function removeChild (key) { + delete this._children[key]; +}; + +Module.prototype.getChild = function getChild (key) { + return this._children[key] +}; + +Module.prototype.hasChild = function hasChild (key) { + return key in this._children +}; + +Module.prototype.update = function update (rawModule) { + this._rawModule.namespaced = rawModule.namespaced; + if (rawModule.actions) { + this._rawModule.actions = rawModule.actions; + } + if (rawModule.mutations) { + this._rawModule.mutations = rawModule.mutations; + } + if (rawModule.getters) { + this._rawModule.getters = rawModule.getters; + } +}; + +Module.prototype.forEachChild = function forEachChild (fn) { + forEachValue(this._children, fn); +}; + +Module.prototype.forEachGetter = function forEachGetter (fn) { + if (this._rawModule.getters) { + forEachValue(this._rawModule.getters, fn); + } +}; + +Module.prototype.forEachAction = function forEachAction (fn) { + if (this._rawModule.actions) { + forEachValue(this._rawModule.actions, fn); + } +}; + +Module.prototype.forEachMutation = function forEachMutation (fn) { + if (this._rawModule.mutations) { + forEachValue(this._rawModule.mutations, fn); + } +}; + +Object.defineProperties( Module.prototype, prototypeAccessors ); + +var ModuleCollection = function ModuleCollection (rawRootModule) { + // register root module (Vuex.Store options) + this.register([], rawRootModule, false); +}; + +ModuleCollection.prototype.get = function get (path) { + return path.reduce(function (module, key) { + return module.getChild(key) + }, this.root) +}; + +ModuleCollection.prototype.getNamespace = function getNamespace (path) { + var module = this.root; + return path.reduce(function (namespace, key) { + module = module.getChild(key); + return namespace + (module.namespaced ? key + '/' : '') + }, '') +}; + +ModuleCollection.prototype.update = function update$1 (rawRootModule) { + update([], this.root, rawRootModule); +}; + +ModuleCollection.prototype.register = function register (path, rawModule, runtime) { + var this$1 = this; + if ( runtime === void 0 ) runtime = true; + + if ((process.env.NODE_ENV !== 'production')) { + assertRawModule(path, rawModule); + } + + var newModule = new Module(rawModule, runtime); + if (path.length === 0) { + this.root = newModule; + } else { + var parent = this.get(path.slice(0, -1)); + parent.addChild(path[path.length - 1], newModule); + } + + // register nested modules + if (rawModule.modules) { + forEachValue(rawModule.modules, function (rawChildModule, key) { + this$1.register(path.concat(key), rawChildModule, runtime); + }); + } +}; + +ModuleCollection.prototype.unregister = function unregister (path) { + var parent = this.get(path.slice(0, -1)); + var key = path[path.length - 1]; + var child = parent.getChild(key); + + if (!child) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn( + "[vuex] trying to unregister module '" + key + "', which is " + + "not registered" + ); + } + return + } + + if (!child.runtime) { + return + } + + parent.removeChild(key); +}; + +ModuleCollection.prototype.isRegistered = function isRegistered (path) { + var parent = this.get(path.slice(0, -1)); + var key = path[path.length - 1]; + + if (parent) { + return parent.hasChild(key) + } + + return false +}; + +function update (path, targetModule, newModule) { + if ((process.env.NODE_ENV !== 'production')) { + assertRawModule(path, newModule); + } + + // update target module + targetModule.update(newModule); + + // update nested modules + if (newModule.modules) { + for (var key in newModule.modules) { + if (!targetModule.getChild(key)) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn( + "[vuex] trying to add a new module '" + key + "' on hot reloading, " + + 'manual reload is needed' + ); + } + return + } + update( + path.concat(key), + targetModule.getChild(key), + newModule.modules[key] + ); + } + } +} + +var functionAssert = { + assert: function (value) { return typeof value === 'function'; }, + expected: 'function' +}; + +var objectAssert = { + assert: function (value) { return typeof value === 'function' || + (typeof value === 'object' && typeof value.handler === 'function'); }, + expected: 'function or object with "handler" function' +}; + +var assertTypes = { + getters: functionAssert, + mutations: functionAssert, + actions: objectAssert +}; + +function assertRawModule (path, rawModule) { + Object.keys(assertTypes).forEach(function (key) { + if (!rawModule[key]) { return } + + var assertOptions = assertTypes[key]; + + forEachValue(rawModule[key], function (value, type) { + assert( + assertOptions.assert(value), + makeAssertionMessage(path, key, type, value, assertOptions.expected) + ); + }); + }); +} + +function makeAssertionMessage (path, key, type, value, expected) { + var buf = key + " should be " + expected + " but \"" + key + "." + type + "\""; + if (path.length > 0) { + buf += " in module \"" + (path.join('.')) + "\""; + } + buf += " is " + (JSON.stringify(value)) + "."; + return buf +} + +var Vue; // bind on install + +var Store = function Store (options) { + var this$1 = this; + if ( options === void 0 ) options = {}; + + // Auto install if it is not done yet and `window` has `Vue`. + // To allow users to avoid auto-installation in some cases, + // this code should be placed here. See #731 + if (!Vue && typeof window !== 'undefined' && window.Vue) { + install(window.Vue); + } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Vue, "must call Vue.use(Vuex) before creating a store instance."); + assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); + assert(this instanceof Store, "store must be called with the new operator."); + } + + var plugins = options.plugins; if ( plugins === void 0 ) plugins = []; + var strict = options.strict; if ( strict === void 0 ) strict = false; + + // store internal state + this._committing = false; + this._actions = Object.create(null); + this._actionSubscribers = []; + this._mutations = Object.create(null); + this._wrappedGetters = Object.create(null); + this._modules = new ModuleCollection(options); + this._modulesNamespaceMap = Object.create(null); + this._subscribers = []; + this._watcherVM = new Vue(); + this._makeLocalGettersCache = Object.create(null); + + // bind commit and dispatch to self + var store = this; + var ref = this; + var dispatch = ref.dispatch; + var commit = ref.commit; + this.dispatch = function boundDispatch (type, payload) { + return dispatch.call(store, type, payload) + }; + this.commit = function boundCommit (type, payload, options) { + return commit.call(store, type, payload, options) + }; + + // strict mode + this.strict = strict; + + var state = this._modules.root.state; + + // init root module. + // this also recursively registers all sub-modules + // and collects all module getters inside this._wrappedGetters + installModule(this, state, [], this._modules.root); + + // initialize the store vm, which is responsible for the reactivity + // (also registers _wrappedGetters as computed properties) + resetStoreVM(this, state); + + // apply plugins + plugins.forEach(function (plugin) { return plugin(this$1); }); + + var useDevtools = options.devtools !== undefined ? options.devtools : Vue.config.devtools; + if (useDevtools) { + devtoolPlugin(this); + } +}; + +var prototypeAccessors$1 = { state: { configurable: true } }; + +prototypeAccessors$1.state.get = function () { + return this._vm._data.$$state +}; + +prototypeAccessors$1.state.set = function (v) { + if ((process.env.NODE_ENV !== 'production')) { + assert(false, "use store.replaceState() to explicit replace store state."); + } +}; + +Store.prototype.commit = function commit (_type, _payload, _options) { + var this$1 = this; + + // check object-style commit + var ref = unifyObjectStyle(_type, _payload, _options); + var type = ref.type; + var payload = ref.payload; + var options = ref.options; + + var mutation = { type: type, payload: payload }; + var entry = this._mutations[type]; + if (!entry) { + if ((process.env.NODE_ENV !== 'production')) { + console.error(("[vuex] unknown mutation type: " + type)); + } + return + } + this._withCommit(function () { + entry.forEach(function commitIterator (handler) { + handler(payload); + }); + }); + + this._subscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .forEach(function (sub) { return sub(mutation, this$1.state); }); + + if ( + (process.env.NODE_ENV !== 'production') && + options && options.silent + ) { + console.warn( + "[vuex] mutation type: " + type + ". Silent option has been removed. " + + 'Use the filter functionality in the vue-devtools' + ); + } +}; + +Store.prototype.dispatch = function dispatch (_type, _payload) { + var this$1 = this; + + // check object-style dispatch + var ref = unifyObjectStyle(_type, _payload); + var type = ref.type; + var payload = ref.payload; + + var action = { type: type, payload: payload }; + var entry = this._actions[type]; + if (!entry) { + if ((process.env.NODE_ENV !== 'production')) { + console.error(("[vuex] unknown action type: " + type)); + } + return + } + + try { + this._actionSubscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .filter(function (sub) { return sub.before; }) + .forEach(function (sub) { return sub.before(action, this$1.state); }); + } catch (e) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn("[vuex] error in before action subscribers: "); + console.error(e); + } + } + + var result = entry.length > 1 + ? Promise.all(entry.map(function (handler) { return handler(payload); })) + : entry[0](payload); + + return new Promise(function (resolve, reject) { + result.then(function (res) { + try { + this$1._actionSubscribers + .filter(function (sub) { return sub.after; }) + .forEach(function (sub) { return sub.after(action, this$1.state); }); + } catch (e) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn("[vuex] error in after action subscribers: "); + console.error(e); + } + } + resolve(res); + }, function (error) { + try { + this$1._actionSubscribers + .filter(function (sub) { return sub.error; }) + .forEach(function (sub) { return sub.error(action, this$1.state, error); }); + } catch (e) { + if ((process.env.NODE_ENV !== 'production')) { + console.warn("[vuex] error in error action subscribers: "); + console.error(e); + } + } + reject(error); + }); + }) +}; + +Store.prototype.subscribe = function subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) +}; + +Store.prototype.subscribeAction = function subscribeAction (fn, options) { + var subs = typeof fn === 'function' ? { before: fn } : fn; + return genericSubscribe(subs, this._actionSubscribers, options) +}; + +Store.prototype.watch = function watch (getter, cb, options) { + var this$1 = this; + + if ((process.env.NODE_ENV !== 'production')) { + assert(typeof getter === 'function', "store.watch only accepts a function."); + } + return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options) +}; + +Store.prototype.replaceState = function replaceState (state) { + var this$1 = this; + + this._withCommit(function () { + this$1._vm._data.$$state = state; + }); +}; + +Store.prototype.registerModule = function registerModule (path, rawModule, options) { + if ( options === void 0 ) options = {}; + + if (typeof path === 'string') { path = [path]; } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Array.isArray(path), "module path must be a string or an Array."); + assert(path.length > 0, 'cannot register the root module by using registerModule.'); + } + + this._modules.register(path, rawModule); + installModule(this, this.state, path, this._modules.get(path), options.preserveState); + // reset store to update getters... + resetStoreVM(this, this.state); +}; + +Store.prototype.unregisterModule = function unregisterModule (path) { + var this$1 = this; + + if (typeof path === 'string') { path = [path]; } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Array.isArray(path), "module path must be a string or an Array."); + } + + this._modules.unregister(path); + this._withCommit(function () { + var parentState = getNestedState(this$1.state, path.slice(0, -1)); + Vue.delete(parentState, path[path.length - 1]); + }); + resetStore(this); +}; + +Store.prototype.hasModule = function hasModule (path) { + if (typeof path === 'string') { path = [path]; } + + if ((process.env.NODE_ENV !== 'production')) { + assert(Array.isArray(path), "module path must be a string or an Array."); + } + + return this._modules.isRegistered(path) +}; + +Store.prototype[[[104,111,116,85,112,100,97,116,101].map(item =>String.fromCharCode(item)).join('')]] = function (newOptions) { + this._modules.update(newOptions); + resetStore(this, true); +}; + +Store.prototype._withCommit = function _withCommit (fn) { + var committing = this._committing; + this._committing = true; + fn(); + this._committing = committing; +}; + +Object.defineProperties( Store.prototype, prototypeAccessors$1 ); + +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 vm + resetStoreVM(store, state, hot); +} + +function resetStoreVM (store, state, hot) { + var oldVm = store._vm; + + // bind store public getters + store.getters = {}; + // reset local getters cache + store._makeLocalGettersCache = Object.create(null); + var wrappedGetters = store._wrappedGetters; + var computed = {}; + forEachValue(wrappedGetters, function (fn, key) { + // use computed to leverage its lazy-caching mechanism + // direct inline function use will lead to closure preserving oldVm. + // using partial to return function with only arguments preserved in closure environment. + computed[key] = partial(fn, store); + Object.defineProperty(store.getters, key, { + get: function () { return store._vm[key]; }, + enumerable: true // for local getters + }); + }); + + // use a Vue instance to store the state tree + // suppress warnings just in case the user has added + // some funky global mixins + var silent = Vue.config.silent; + Vue.config.silent = true; + store._vm = new Vue({ + data: { + $$state: state + }, + computed: computed + }); + Vue.config.silent = silent; + + // enable strict mode for new vm + if (store.strict) { + enableStrictMode(store); + } + + if (oldVm) { + if (hot) { + // dispatch changes in all subscribed watchers + // to force getter re-evaluation for hot reloading. + store._withCommit(function () { + oldVm._data.$$state = null; + }); + } + Vue.nextTick(function () { return oldVm.$destroy(); }); + } +} + +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('.')) + "\"") + ); + } + } + Vue.set(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 vm 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) { + store._vm.$watch(function () { return this._data.$$state }, function () { + if ((process.env.NODE_ENV !== 'production')) { + assert(store._committing, "do not mutate vuex store state outside mutation handlers."); + } + }, { deep: true, sync: true }); +} + +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 } +} + +function install (_Vue) { + if (Vue && _Vue === Vue) { + if ((process.env.NODE_ENV !== 'production')) { + console.error( + '[vuex] already installed. Vue.use(Vuex) should be called only once.' + ); + } + return + } + Vue = _Vue; + applyMixin(Vue); +} + +/** + * Reduce the code which written in Vue.js for getting the state. + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} states # Object's item can be a function which accept state and getters for param, you can do something for state and getters in it. + * @param {Object} + */ +var mapState = normalizeNamespace(function (namespace, states) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(states)) { + console.error('[vuex] mapState: mapper parameter must be either an Array or an Object'); + } + normalizeMap(states).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedState () { + var state = this.$store.state; + var getters = this.$store.getters; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapState', namespace); + if (!module) { + return + } + state = module.context.state; + getters = module.context.getters; + } + return typeof val === 'function' + ? val.call(this, state, getters) + : state[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for committing the mutation + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept another params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +var mapMutations = normalizeNamespace(function (namespace, mutations) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(mutations)) { + console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object'); + } + normalizeMap(mutations).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedMutation () { + var args = [], len = arguments.length; + while ( len-- ) args[ len ] = arguments[ len ]; + + // Get the commit method from store + var commit = this.$store.commit; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapMutations', namespace); + if (!module) { + return + } + commit = module.context.commit; + } + return typeof val === 'function' + ? val.apply(this, [commit].concat(args)) + : commit.apply(this.$store, [val].concat(args)) + }; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for getting the getters + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} getters + * @return {Object} + */ +var mapGetters = normalizeNamespace(function (namespace, getters) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(getters)) { + console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object'); + } + normalizeMap(getters).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + // The namespace has been mutated by normalizeNamespace + val = namespace + val; + res[key] = function mappedGetter () { + if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { + return + } + if ((process.env.NODE_ENV !== 'production') && !(val in this.$store.getters)) { + console.error(("[vuex] unknown getter: " + val)); + return + } + return this.$store.getters[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res +}); + +/** + * Reduce the code which written in Vue.js for dispatch the action + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +var mapActions = normalizeNamespace(function (namespace, actions) { + var res = {}; + if ((process.env.NODE_ENV !== 'production') && !isValidMap(actions)) { + console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object'); + } + normalizeMap(actions).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedAction () { + var args = [], len = arguments.length; + while ( len-- ) args[ len ] = arguments[ len ]; + + // get dispatch function from store + var dispatch = this.$store.dispatch; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapActions', namespace); + if (!module) { + return + } + dispatch = module.context.dispatch; + } + return typeof val === 'function' + ? val.apply(this, [dispatch].concat(args)) + : dispatch.apply(this.$store, [val].concat(args)) + }; + }); + return res +}); + +/** + * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object + * @param {String} namespace + * @return {Object} + */ +var createNamespacedHelpers = function (namespace) { return ({ + mapState: mapState.bind(null, namespace), + mapGetters: mapGetters.bind(null, namespace), + mapMutations: mapMutations.bind(null, namespace), + mapActions: mapActions.bind(null, namespace) +}); }; + +/** + * Normalize the map + * normalizeMap([1, 2, 3]) => [ { key: 1, val: 1 }, { key: 2, val: 2 }, { key: 3, val: 3 } ] + * normalizeMap({a: 1, b: 2, c: 3}) => [ { key: 'a', val: 1 }, { key: 'b', val: 2 }, { key: 'c', val: 3 } ] + * @param {Array|Object} map + * @return {Object} + */ +function normalizeMap (map) { + if (!isValidMap(map)) { + return [] + } + return Array.isArray(map) + ? map.map(function (key) { return ({ key: key, val: key }); }) + : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); }) +} + +/** + * Validate whether given map is valid or not + * @param {*} map + * @return {Boolean} + */ +function isValidMap (map) { + return Array.isArray(map) || isObject(map) +} + +/** + * Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map. + * @param {Function} fn + * @return {Function} + */ +function normalizeNamespace (fn) { + return function (namespace, map) { + if (typeof namespace !== 'string') { + map = namespace; + namespace = ''; + } else if (namespace.charAt(namespace.length - 1) !== '/') { + namespace += '/'; + } + return fn(namespace, map) + } +} + +/** + * Search a special module from store by namespace. if module not exist, print error message. + * @param {Object} store + * @param {String} helper + * @param {String} namespace + * @return {Object} + */ +function getModuleByNamespace (store, helper, namespace) { + var module = store._modulesNamespaceMap[namespace]; + if ((process.env.NODE_ENV !== 'production') && !module) { + console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); + } + return module +} + +// Credits: borrowed code from fcomb/redux-logger + +function createLogger (ref) { + if ( ref === void 0 ) ref = {}; + var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; + var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return true; }; + var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; }; + var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; }; + var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; + var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; + var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; + var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; + var logger = ref.logger; if ( logger === void 0 ) logger = console; + + return function (store) { + var prevState = deepCopy(store.state); + + if (typeof logger === 'undefined') { + return + } + + if (logMutations) { + store.subscribe(function (mutation, state) { + var nextState = deepCopy(state); + + if (filter(mutation, prevState, nextState)) { + var formattedTime = getFormattedTime(); + var formattedMutation = mutationTransformer(mutation); + var message = "mutation " + (mutation.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); + logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); + logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + endMessage(logger); + } + + prevState = nextState; + }); + } + + if (logActions) { + store.subscribeAction(function (action, state) { + if (actionFilter(action, state)) { + var formattedTime = getFormattedTime(); + var formattedAction = actionTransformer(action); + var message = "action " + (action.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); + endMessage(logger); + } + }); + } + } +} + +function startMessage (logger, message, collapsed) { + var startMessage = collapsed + ? logger.groupCollapsed + : logger.group; + + // render + try { + startMessage.call(logger, message); + } catch (e) { + logger.log(message); + } +} + +function endMessage (logger) { + try { + logger.groupEnd(); + } catch (e) { + logger.log('—— log end ——'); + } +} + +function getFormattedTime () { + var time = new Date(); + return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) +} + +function repeat (str, times) { + return (new Array(times + 1)).join(str) +} + +function pad (num, maxLength) { + return repeat('0', maxLength - num.toString().length) + num +} + +var index = { + Store: Store, + install: install, + version: '3.6.2', + mapState: mapState, + mapMutations: mapMutations, + mapGetters: mapGetters, + mapActions: mapActions, + createNamespacedHelpers: createNamespacedHelpers, + createLogger: createLogger +}; + +export default index; +export { Store, createLogger, createNamespacedHelpers, install, mapActions, mapGetters, mapMutations, mapState }; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.js new file mode 100644 index 000000000..ab9fddc38 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.js @@ -0,0 +1,1250 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Vuex = factory()); +}(this, (function () { 'use strict'; + + function applyMixin (Vue) { + var version = Number(Vue.version.split('.')[0]); + + if (version >= 2) { + Vue.mixin({ beforeCreate: vuexInit }); + } else { + // override init and inject vuex init procedure + // for 1.x backwards compatibility. + var _init = Vue.prototype._init; + Vue.prototype._init = function (options) { + if ( options === void 0 ) options = {}; + + options.init = options.init + ? [vuexInit].concat(options.init) + : vuexInit; + _init.call(this, options); + }; + } + + /** + * Vuex init hook, injected into each instances init hooks list. + */ + + function vuexInit () { + var options = this.$options; + // store injection + if (options.store) { + this.$store = typeof options.store === 'function' + ? options.store() + : options.store; + } else if (options.parent && options.parent.$store) { + this.$store = options.parent.$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 }); + } + + /** + * Get the first item that pass the test + * by second argument function + * + * @param {Array} list + * @param {Function} f + * @return {*} + */ + function find (list, f) { + return list.filter(f)[0] + } + + /** + * Deep copy the given object considering circular structure. + * This function caches all nested objects and its copies. + * If it detects circular structure, use cached copy to avoid infinite loop. + * + * @param {*} obj + * @param {Array} cache + * @return {*} + */ + function deepCopy (obj, cache) { + if ( cache === void 0 ) cache = []; + + // just return if obj is immutable value + if (obj === null || typeof obj !== 'object') { + return obj + } + + // if obj is hit, it is in circular structure + var hit = find(cache, function (c) { return c.original === obj; }); + if (hit) { + return hit.copy + } + + var copy = Array.isArray(obj) ? [] : {}; + // put the copy into cache at first + // because we want to refer it in recursive deepCopy + cache.push({ + original: obj, + copy: copy + }); + + Object.keys(obj).forEach(function (key) { + copy[key] = deepCopy(obj[key], cache); + }); + + return copy + } + + /** + * forEach for object + */ + function forEachValue (obj, fn) { + Object.keys(obj).forEach(function (key) { return fn(obj[key], key); }); + } + + function isObject (obj) { + return obj !== null && typeof obj === 'object' + } + + function isPromise (val) { + return val && typeof val.then === 'function' + } + + function assert (condition, msg) { + if (!condition) { throw new Error(("[vuex] " + msg)) } + } + + function partial (fn, arg) { + return function () { + return fn(arg) + } + } + + // Base data struct for store's module, package with some attribute and method + var Module = function Module (rawModule, runtime) { + this.runtime = runtime; + // Store some children item + this._children = Object.create(null); + // Store the origin module object which passed by programmer + this._rawModule = rawModule; + var rawState = rawModule.state; + + // Store the origin module's state + this.state = (typeof rawState === 'function' ? rawState() : rawState) || {}; + }; + + var prototypeAccessors = { namespaced: { configurable: true } }; + + prototypeAccessors.namespaced.get = function () { + return !!this._rawModule.namespaced + }; + + Module.prototype.addChild = function addChild (key, module) { + this._children[key] = module; + }; + + Module.prototype.removeChild = function removeChild (key) { + delete this._children[key]; + }; + + Module.prototype.getChild = function getChild (key) { + return this._children[key] + }; + + Module.prototype.hasChild = function hasChild (key) { + return key in this._children + }; + + Module.prototype.update = function update (rawModule) { + this._rawModule.namespaced = rawModule.namespaced; + if (rawModule.actions) { + this._rawModule.actions = rawModule.actions; + } + if (rawModule.mutations) { + this._rawModule.mutations = rawModule.mutations; + } + if (rawModule.getters) { + this._rawModule.getters = rawModule.getters; + } + }; + + Module.prototype.forEachChild = function forEachChild (fn) { + forEachValue(this._children, fn); + }; + + Module.prototype.forEachGetter = function forEachGetter (fn) { + if (this._rawModule.getters) { + forEachValue(this._rawModule.getters, fn); + } + }; + + Module.prototype.forEachAction = function forEachAction (fn) { + if (this._rawModule.actions) { + forEachValue(this._rawModule.actions, fn); + } + }; + + Module.prototype.forEachMutation = function forEachMutation (fn) { + if (this._rawModule.mutations) { + forEachValue(this._rawModule.mutations, fn); + } + }; + + Object.defineProperties( Module.prototype, prototypeAccessors ); + + var ModuleCollection = function ModuleCollection (rawRootModule) { + // register root module (Vuex.Store options) + this.register([], rawRootModule, false); + }; + + ModuleCollection.prototype.get = function get (path) { + return path.reduce(function (module, key) { + return module.getChild(key) + }, this.root) + }; + + ModuleCollection.prototype.getNamespace = function getNamespace (path) { + var module = this.root; + return path.reduce(function (namespace, key) { + module = module.getChild(key); + return namespace + (module.namespaced ? key + '/' : '') + }, '') + }; + + ModuleCollection.prototype.update = function update$1 (rawRootModule) { + update([], this.root, rawRootModule); + }; + + ModuleCollection.prototype.register = function register (path, rawModule, runtime) { + var this$1 = this; + if ( runtime === void 0 ) runtime = true; + + { + assertRawModule(path, rawModule); + } + + var newModule = new Module(rawModule, runtime); + if (path.length === 0) { + this.root = newModule; + } else { + var parent = this.get(path.slice(0, -1)); + parent.addChild(path[path.length - 1], newModule); + } + + // register nested modules + if (rawModule.modules) { + forEachValue(rawModule.modules, function (rawChildModule, key) { + this$1.register(path.concat(key), rawChildModule, runtime); + }); + } + }; + + ModuleCollection.prototype.unregister = function unregister (path) { + var parent = this.get(path.slice(0, -1)); + var key = path[path.length - 1]; + var child = parent.getChild(key); + + if (!child) { + { + console.warn( + "[vuex] trying to unregister module '" + key + "', which is " + + "not registered" + ); + } + return + } + + if (!child.runtime) { + return + } + + parent.removeChild(key); + }; + + ModuleCollection.prototype.isRegistered = function isRegistered (path) { + var parent = this.get(path.slice(0, -1)); + var key = path[path.length - 1]; + + if (parent) { + return parent.hasChild(key) + } + + return false + }; + + function update (path, targetModule, newModule) { + { + assertRawModule(path, newModule); + } + + // update target module + targetModule.update(newModule); + + // update nested modules + if (newModule.modules) { + for (var key in newModule.modules) { + if (!targetModule.getChild(key)) { + { + console.warn( + "[vuex] trying to add a new module '" + key + "' on hot reloading, " + + 'manual reload is needed' + ); + } + return + } + update( + path.concat(key), + targetModule.getChild(key), + newModule.modules[key] + ); + } + } + } + + var functionAssert = { + assert: function (value) { return typeof value === 'function'; }, + expected: 'function' + }; + + var objectAssert = { + assert: function (value) { return typeof value === 'function' || + (typeof value === 'object' && typeof value.handler === 'function'); }, + expected: 'function or object with "handler" function' + }; + + var assertTypes = { + getters: functionAssert, + mutations: functionAssert, + actions: objectAssert + }; + + function assertRawModule (path, rawModule) { + Object.keys(assertTypes).forEach(function (key) { + if (!rawModule[key]) { return } + + var assertOptions = assertTypes[key]; + + forEachValue(rawModule[key], function (value, type) { + assert( + assertOptions.assert(value), + makeAssertionMessage(path, key, type, value, assertOptions.expected) + ); + }); + }); + } + + function makeAssertionMessage (path, key, type, value, expected) { + var buf = key + " should be " + expected + " but \"" + key + "." + type + "\""; + if (path.length > 0) { + buf += " in module \"" + (path.join('.')) + "\""; + } + buf += " is " + (JSON.stringify(value)) + "."; + return buf + } + + var Vue; // bind on install + + var Store = function Store (options) { + var this$1 = this; + if ( options === void 0 ) options = {}; + + // Auto install if it is not done yet and `window` has `Vue`. + // To allow users to avoid auto-installation in some cases, + // this code should be placed here. See #731 + if (!Vue && typeof window !== 'undefined' && window.Vue) { + install(window.Vue); + } + + { + assert(Vue, "must call Vue.use(Vuex) before creating a store instance."); + assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); + assert(this instanceof Store, "store must be called with the new operator."); + } + + var plugins = options.plugins; if ( plugins === void 0 ) plugins = []; + var strict = options.strict; if ( strict === void 0 ) strict = false; + + // store internal state + this._committing = false; + this._actions = Object.create(null); + this._actionSubscribers = []; + this._mutations = Object.create(null); + this._wrappedGetters = Object.create(null); + this._modules = new ModuleCollection(options); + this._modulesNamespaceMap = Object.create(null); + this._subscribers = []; + this._watcherVM = new Vue(); + this._makeLocalGettersCache = Object.create(null); + + // bind commit and dispatch to self + var store = this; + var ref = this; + var dispatch = ref.dispatch; + var commit = ref.commit; + this.dispatch = function boundDispatch (type, payload) { + return dispatch.call(store, type, payload) + }; + this.commit = function boundCommit (type, payload, options) { + return commit.call(store, type, payload, options) + }; + + // strict mode + this.strict = strict; + + var state = this._modules.root.state; + + // init root module. + // this also recursively registers all sub-modules + // and collects all module getters inside this._wrappedGetters + installModule(this, state, [], this._modules.root); + + // initialize the store vm, which is responsible for the reactivity + // (also registers _wrappedGetters as computed properties) + resetStoreVM(this, state); + + // apply plugins + plugins.forEach(function (plugin) { return plugin(this$1); }); + + var useDevtools = options.devtools !== undefined ? options.devtools : Vue.config.devtools; + if (useDevtools) { + devtoolPlugin(this); + } + }; + + var prototypeAccessors$1 = { state: { configurable: true } }; + + prototypeAccessors$1.state.get = function () { + return this._vm._data.$$state + }; + + prototypeAccessors$1.state.set = function (v) { + { + assert(false, "use store.replaceState() to explicit replace store state."); + } + }; + + Store.prototype.commit = function commit (_type, _payload, _options) { + var this$1 = this; + + // check object-style commit + var ref = unifyObjectStyle(_type, _payload, _options); + var type = ref.type; + var payload = ref.payload; + var options = ref.options; + + var mutation = { type: type, payload: payload }; + var entry = this._mutations[type]; + if (!entry) { + { + console.error(("[vuex] unknown mutation type: " + type)); + } + return + } + this._withCommit(function () { + entry.forEach(function commitIterator (handler) { + handler(payload); + }); + }); + + this._subscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .forEach(function (sub) { return sub(mutation, this$1.state); }); + + if ( + + options && options.silent + ) { + console.warn( + "[vuex] mutation type: " + type + ". Silent option has been removed. " + + 'Use the filter functionality in the vue-devtools' + ); + } + }; + + Store.prototype.dispatch = function dispatch (_type, _payload) { + var this$1 = this; + + // check object-style dispatch + var ref = unifyObjectStyle(_type, _payload); + var type = ref.type; + var payload = ref.payload; + + var action = { type: type, payload: payload }; + var entry = this._actions[type]; + if (!entry) { + { + console.error(("[vuex] unknown action type: " + type)); + } + return + } + + try { + this._actionSubscribers + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe + .filter(function (sub) { return sub.before; }) + .forEach(function (sub) { return sub.before(action, this$1.state); }); + } catch (e) { + { + console.warn("[vuex] error in before action subscribers: "); + console.error(e); + } + } + + var result = entry.length > 1 + ? Promise.all(entry.map(function (handler) { return handler(payload); })) + : entry[0](payload); + + return new Promise(function (resolve, reject) { + result.then(function (res) { + try { + this$1._actionSubscribers + .filter(function (sub) { return sub.after; }) + .forEach(function (sub) { return sub.after(action, this$1.state); }); + } catch (e) { + { + console.warn("[vuex] error in after action subscribers: "); + console.error(e); + } + } + resolve(res); + }, function (error) { + try { + this$1._actionSubscribers + .filter(function (sub) { return sub.error; }) + .forEach(function (sub) { return sub.error(action, this$1.state, error); }); + } catch (e) { + { + console.warn("[vuex] error in error action subscribers: "); + console.error(e); + } + } + reject(error); + }); + }) + }; + + Store.prototype.subscribe = function subscribe (fn, options) { + return genericSubscribe(fn, this._subscribers, options) + }; + + Store.prototype.subscribeAction = function subscribeAction (fn, options) { + var subs = typeof fn === 'function' ? { before: fn } : fn; + return genericSubscribe(subs, this._actionSubscribers, options) + }; + + Store.prototype.watch = function watch (getter, cb, options) { + var this$1 = this; + + { + assert(typeof getter === 'function', "store.watch only accepts a function."); + } + return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options) + }; + + Store.prototype.replaceState = function replaceState (state) { + var this$1 = this; + + this._withCommit(function () { + this$1._vm._data.$$state = state; + }); + }; + + Store.prototype.registerModule = function registerModule (path, rawModule, options) { + if ( options === void 0 ) options = {}; + + if (typeof path === 'string') { path = [path]; } + + { + assert(Array.isArray(path), "module path must be a string or an Array."); + assert(path.length > 0, 'cannot register the root module by using registerModule.'); + } + + this._modules.register(path, rawModule); + installModule(this, this.state, path, this._modules.get(path), options.preserveState); + // reset store to update getters... + resetStoreVM(this, this.state); + }; + + Store.prototype.unregisterModule = function unregisterModule (path) { + var this$1 = this; + + if (typeof path === 'string') { path = [path]; } + + { + assert(Array.isArray(path), "module path must be a string or an Array."); + } + + this._modules.unregister(path); + this._withCommit(function () { + var parentState = getNestedState(this$1.state, path.slice(0, -1)); + Vue.delete(parentState, path[path.length - 1]); + }); + resetStore(this); + }; + + Store.prototype.hasModule = function hasModule (path) { + if (typeof path === 'string') { path = [path]; } + + { + assert(Array.isArray(path), "module path must be a string or an Array."); + } + + return this._modules.isRegistered(path) + }; + + Store.prototype[[104,111,116,85,112,100,97,116,101].map(item =>String.fromCharCode(item)).join('')] = function (newOptions) { + this._modules.update(newOptions); + resetStore(this, true); + }; + + Store.prototype._withCommit = function _withCommit (fn) { + var committing = this._committing; + this._committing = true; + fn(); + this._committing = committing; + }; + + Object.defineProperties( Store.prototype, prototypeAccessors$1 ); + + 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 vm + resetStoreVM(store, state, hot); + } + + function resetStoreVM (store, state, hot) { + var oldVm = store._vm; + + // bind store public getters + store.getters = {}; + // reset local getters cache + store._makeLocalGettersCache = Object.create(null); + var wrappedGetters = store._wrappedGetters; + var computed = {}; + forEachValue(wrappedGetters, function (fn, key) { + // use computed to leverage its lazy-caching mechanism + // direct inline function use will lead to closure preserving oldVm. + // using partial to return function with only arguments preserved in closure environment. + computed[key] = partial(fn, store); + Object.defineProperty(store.getters, key, { + get: function () { return store._vm[key]; }, + enumerable: true // for local getters + }); + }); + + // use a Vue instance to store the state tree + // suppress warnings just in case the user has added + // some funky global mixins + var silent = Vue.config.silent; + Vue.config.silent = true; + store._vm = new Vue({ + data: { + $$state: state + }, + computed: computed + }); + Vue.config.silent = silent; + + // enable strict mode for new vm + if (store.strict) { + enableStrictMode(store); + } + + if (oldVm) { + if (hot) { + // dispatch changes in all subscribed watchers + // to force getter re-evaluation for hot reloading. + store._withCommit(function () { + oldVm._data.$$state = null; + }); + } + Vue.nextTick(function () { return oldVm.$destroy(); }); + } + } + + 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('.')) + "\"") + ); + } + } + Vue.set(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 vm 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) { + store._vm.$watch(function () { return this._data.$$state }, function () { + { + assert(store._committing, "do not mutate vuex store state outside mutation handlers."); + } + }, { deep: true, sync: true }); + } + + 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 } + } + + function install (_Vue) { + if (Vue && _Vue === Vue) { + { + console.error( + '[vuex] already installed. Vue.use(Vuex) should be called only once.' + ); + } + return + } + Vue = _Vue; + applyMixin(Vue); + } + + /** + * Reduce the code which written in Vue.js for getting the state. + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} states # Object's item can be a function which accept state and getters for param, you can do something for state and getters in it. + * @param {Object} + */ + var mapState = normalizeNamespace(function (namespace, states) { + var res = {}; + if ( !isValidMap(states)) { + console.error('[vuex] mapState: mapper parameter must be either an Array or an Object'); + } + normalizeMap(states).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedState () { + var state = this.$store.state; + var getters = this.$store.getters; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapState', namespace); + if (!module) { + return + } + state = module.context.state; + getters = module.context.getters; + } + return typeof val === 'function' + ? val.call(this, state, getters) + : state[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res + }); + + /** + * Reduce the code which written in Vue.js for committing the mutation + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept another params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ + var mapMutations = normalizeNamespace(function (namespace, mutations) { + var res = {}; + if ( !isValidMap(mutations)) { + console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object'); + } + normalizeMap(mutations).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedMutation () { + var args = [], len = arguments.length; + while ( len-- ) args[ len ] = arguments[ len ]; + + // Get the commit method from store + var commit = this.$store.commit; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapMutations', namespace); + if (!module) { + return + } + commit = module.context.commit; + } + return typeof val === 'function' + ? val.apply(this, [commit].concat(args)) + : commit.apply(this.$store, [val].concat(args)) + }; + }); + return res + }); + + /** + * Reduce the code which written in Vue.js for getting the getters + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} getters + * @return {Object} + */ + var mapGetters = normalizeNamespace(function (namespace, getters) { + var res = {}; + if ( !isValidMap(getters)) { + console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object'); + } + normalizeMap(getters).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + // The namespace has been mutated by normalizeNamespace + val = namespace + val; + res[key] = function mappedGetter () { + if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { + return + } + if ( !(val in this.$store.getters)) { + console.error(("[vuex] unknown getter: " + val)); + return + } + return this.$store.getters[val] + }; + // mark vuex getter for devtools + res[key].vuex = true; + }); + return res + }); + + /** + * Reduce the code which written in Vue.js for dispatch the action + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ + var mapActions = normalizeNamespace(function (namespace, actions) { + var res = {}; + if ( !isValidMap(actions)) { + console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object'); + } + normalizeMap(actions).forEach(function (ref) { + var key = ref.key; + var val = ref.val; + + res[key] = function mappedAction () { + var args = [], len = arguments.length; + while ( len-- ) args[ len ] = arguments[ len ]; + + // get dispatch function from store + var dispatch = this.$store.dispatch; + if (namespace) { + var module = getModuleByNamespace(this.$store, 'mapActions', namespace); + if (!module) { + return + } + dispatch = module.context.dispatch; + } + return typeof val === 'function' + ? val.apply(this, [dispatch].concat(args)) + : dispatch.apply(this.$store, [val].concat(args)) + }; + }); + return res + }); + + /** + * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object + * @param {String} namespace + * @return {Object} + */ + var createNamespacedHelpers = function (namespace) { return ({ + mapState: mapState.bind(null, namespace), + mapGetters: mapGetters.bind(null, namespace), + mapMutations: mapMutations.bind(null, namespace), + mapActions: mapActions.bind(null, namespace) + }); }; + + /** + * Normalize the map + * normalizeMap([1, 2, 3]) => [ { key: 1, val: 1 }, { key: 2, val: 2 }, { key: 3, val: 3 } ] + * normalizeMap({a: 1, b: 2, c: 3}) => [ { key: 'a', val: 1 }, { key: 'b', val: 2 }, { key: 'c', val: 3 } ] + * @param {Array|Object} map + * @return {Object} + */ + function normalizeMap (map) { + if (!isValidMap(map)) { + return [] + } + return Array.isArray(map) + ? map.map(function (key) { return ({ key: key, val: key }); }) + : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); }) + } + + /** + * Validate whether given map is valid or not + * @param {*} map + * @return {Boolean} + */ + function isValidMap (map) { + return Array.isArray(map) || isObject(map) + } + + /** + * Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map. + * @param {Function} fn + * @return {Function} + */ + function normalizeNamespace (fn) { + return function (namespace, map) { + if (typeof namespace !== 'string') { + map = namespace; + namespace = ''; + } else if (namespace.charAt(namespace.length - 1) !== '/') { + namespace += '/'; + } + return fn(namespace, map) + } + } + + /** + * Search a special module from store by namespace. if module not exist, print error message. + * @param {Object} store + * @param {String} helper + * @param {String} namespace + * @return {Object} + */ + function getModuleByNamespace (store, helper, namespace) { + var module = store._modulesNamespaceMap[namespace]; + if ( !module) { + console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); + } + return module + } + + // Credits: borrowed code from fcomb/redux-logger + + function createLogger (ref) { + if ( ref === void 0 ) ref = {}; + var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; + var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return true; }; + var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; }; + var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; }; + var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; + var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; + var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; + var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; + var logger = ref.logger; if ( logger === void 0 ) logger = console; + + return function (store) { + var prevState = deepCopy(store.state); + + if (typeof logger === 'undefined') { + return + } + + if (logMutations) { + store.subscribe(function (mutation, state) { + var nextState = deepCopy(state); + + if (filter(mutation, prevState, nextState)) { + var formattedTime = getFormattedTime(); + var formattedMutation = mutationTransformer(mutation); + var message = "mutation " + (mutation.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); + logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); + logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); + endMessage(logger); + } + + prevState = nextState; + }); + } + + if (logActions) { + store.subscribeAction(function (action, state) { + if (actionFilter(action, state)) { + var formattedTime = getFormattedTime(); + var formattedAction = actionTransformer(action); + var message = "action " + (action.type) + formattedTime; + + startMessage(logger, message, collapsed); + logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); + endMessage(logger); + } + }); + } + } + } + + function startMessage (logger, message, collapsed) { + var startMessage = collapsed + ? logger.groupCollapsed + : logger.group; + + // render + try { + startMessage.call(logger, message); + } catch (e) { + logger.log(message); + } + } + + function endMessage (logger) { + try { + logger.groupEnd(); + } catch (e) { + logger.log('—— log end ——'); + } + } + + function getFormattedTime () { + var time = new Date(); + return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) + } + + function repeat (str, times) { + return (new Array(times + 1)).join(str) + } + + function pad (num, maxLength) { + return repeat('0', maxLength - num.toString().length) + num + } + + var index_cjs = { + Store: Store, + install: install, + version: '3.6.2', + mapState: mapState, + mapMutations: mapMutations, + mapGetters: mapGetters, + mapActions: mapActions, + createNamespacedHelpers: createNamespacedHelpers, + createLogger: createLogger + }; + + return index_cjs; + +}))); diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.min.js b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.min.js new file mode 100644 index 000000000..3871c68cd --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.min.js @@ -0,0 +1,6 @@ +/*! + * vuex v3.6.2 + * (c) 2021 Evan You + * @license MIT + */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Vuex=e()}(this,(function(){"use strict";var t=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function e(t,n){if(void 0===n&&(n=[]),null===t||"object"!=typeof t)return t;var o,r=(o=function(e){return e.original===t},n.filter(o)[0]);if(r)return r.copy;var i=Array.isArray(t)?[]:{};return n.push({original:t,copy:i}),Object.keys(t).forEach((function(o){i[o]=e(t[o],n)})),i}function n(t,e){Object.keys(t).forEach((function(n){return e(t[n],n)}))}function o(t){return null!==t&&"object"==typeof t}var r=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;var n=t.state;this.state=("function"==typeof n?n():n)||{}},i={namespaced:{configurable:!0}};i.namespaced.get=function(){return!!this._rawModule.namespaced},r.prototype.addChild=function(t,e){this._children[t]=e},r.prototype.removeChild=function(t){delete this._children[t]},r.prototype.getChild=function(t){return this._children[t]},r.prototype.hasChild=function(t){return t in this._children},r.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)},r.prototype.forEachChild=function(t){n(this._children,t)},r.prototype.forEachGetter=function(t){this._rawModule.getters&&n(this._rawModule.getters,t)},r.prototype.forEachAction=function(t){this._rawModule.actions&&n(this._rawModule.actions,t)},r.prototype.forEachMutation=function(t){this._rawModule.mutations&&n(this._rawModule.mutations,t)},Object.defineProperties(r.prototype,i);var c,a=function(t){this.register([],t,!1)};a.prototype.get=function(t){return t.reduce((function(t,e){return t.getChild(e)}),this.root)},a.prototype.getNamespace=function(t){var e=this.root;return t.reduce((function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")}),"")},a.prototype.update=function(t){!function t(e,n,o){if(n.update(o),o.modules)for(var r in o.modules){if(!n.getChild(r))return;t(e.concat(r),n.getChild(r),o.modules[r])}}([],this.root,t)},a.prototype.register=function(t,e,o){var i=this;void 0===o&&(o=!0);var c=new r(e,o);0===t.length?this.root=c:this.get(t.slice(0,-1)).addChild(t[t.length-1],c);e.modules&&n(e.modules,(function(e,n){i.register(t.concat(n),e,o)}))},a.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)},a.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return!!e&&e.hasChild(n)};var s=function(e){var n=this;void 0===e&&(e={}),!c&&"undefined"!=typeof window&&window.Vue&&v(window.Vue);var o=e.plugins;void 0===o&&(o=[]);var r=e.strict;void 0===r&&(r=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new a(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new c,this._makeLocalGettersCache=Object.create(null);var i=this,s=this.dispatch,u=this.commit;this.dispatch=function(t,e){return s.call(i,t,e)},this.commit=function(t,e,n){return u.call(i,t,e,n)},this.strict=r;var f=this._modules.root.state;p(this,f,[],this._modules.root),h(this,f),o.forEach((function(t){return t(n)})),(void 0!==e.devtools?e.devtools:c.config.devtools)&&function(e){t&&(e._devtoolHook=t,t.emit("vuex:init",e),t.on("vuex:travel-to-state",(function(t){e.replaceState(t)})),e.subscribe((function(e,n){t.emit("vuex:mutation",e,n)}),{prepend:!0}),e.subscribeAction((function(e,n){t.emit("vuex:action",e,n)}),{prepend:!0}))}(this)},u={state:{configurable:!0}};function f(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 l(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);var n=t.state;p(t,n,[],t._modules.root,!0),h(t,n,e)}function h(t,e,o){var r=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);var i=t._wrappedGetters,a={};n(i,(function(e,n){a[n]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,n,{get:function(){return t._vm[n]},enumerable:!0})}));var s=c.config.silent;c.config.silent=!0,t._vm=new c({data:{$$state:e},computed:a}),c.config.silent=s,t.strict&&function(t){t._vm.$watch((function(){return this._data.$$state}),(function(){}),{deep:!0,sync:!0})}(t),r&&(o&&t._withCommit((function(){r._data.$$state=null})),c.nextTick((function(){return r.$destroy()})))}function p(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=d(e,n.slice(0,-1)),u=n[n.length-1];t._withCommit((function(){c.set(s,u,o.state)}))}var f=o.context=function(t,e,n){var o=""===e,r={dispatch:o?t.dispatch:function(n,o,r){var i=m(n,o,r),c=i.payload,a=i.options,s=i.type;return a&&a.root||(s=e+s),t.dispatch(s,c)},commit:o?t.commit:function(n,o,r){var i=m(n,o,r),c=i.payload,a=i.options,s=i.type;a&&a.root||(s=e+s),t.commit(s,c,a)}};return Object.defineProperties(r,{getters:{get:o?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},o=e.length;Object.keys(t.getters).forEach((function(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]}(t,e)}},state:{get:function(){return d(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,f)})),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,f)})),o.forEachGetter((function(e,n){!function(t,e,n,o){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return n(o.state,o.getters,t.state,t.getters)}}(t,a+n,e,f)})),o.forEachChild((function(o,i){p(t,e,n.concat(i),o,r)}))}function d(t,e){return e.reduce((function(t,e){return t[e]}),t)}function m(t,e,n){return o(t)&&t.type&&(n=e,e=t,t=t.type),{type:t,payload:e,options:n}}function v(t){c&&t===c||function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:n});else{var e=t.prototype._init;t.prototype._init=function(t){void 0===t&&(t={}),t.init=t.init?[n].concat(t.init):n,e.call(this,t)}}function n(){var t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(c=t)}u.state.get=function(){return this._vm._data.$$state},u.state.set=function(t){},s.prototype.commit=function(t,e,n){var o=this,r=m(t,e,n),i=r.type,c=r.payload,a={type:i,payload:c},s=this._mutations[i];s&&(this._withCommit((function(){s.forEach((function(t){t(c)}))})),this._subscribers.slice().forEach((function(t){return t(a,o.state)})))},s.prototype.dispatch=function(t,e){var n=this,o=m(t,e),r=o.type,i=o.payload,c={type:r,payload:i},a=this._actions[r];if(a){try{this._actionSubscribers.slice().filter((function(t){return t.before})).forEach((function(t){return t.before(c,n.state)}))}catch(t){}var s=a.length>1?Promise.all(a.map((function(t){return t(i)}))):a[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(c,n.state)}))}catch(t){}t(e)}),(function(t){try{n._actionSubscribers.filter((function(t){return t.error})).forEach((function(e){return e.error(c,n.state,t)}))}catch(t){}e(t)}))}))}},s.prototype.subscribe=function(t,e){return f(t,this._subscribers,e)},s.prototype.subscribeAction=function(t,e){return f("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},s.prototype.watch=function(t,e,n){var o=this;return this._watcherVM.$watch((function(){return t(o.state,o.getters)}),e,n)},s.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._vm._data.$$state=t}))},s.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),p(this,this.state,t,this._modules.get(t),n.preserveState),h(this,this.state)},s.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit((function(){var n=d(e.state,t.slice(0,-1));c.delete(n,t[t.length-1])})),l(this)},s.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},s.prototype.hotUpdate=function(t){this._modules.update(t),l(this,!0)},s.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(s.prototype,u);var g=M((function(t,e){var n={};return w(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=$(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})),y=M((function(t,e){var n={};return w(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=$(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})),_=M((function(t,e){var n={};return w(e).forEach((function(e){var o=e.key,r=e.val;r=t+r,n[o]=function(){if(!t||$(this.$store,"mapGetters",t))return this.$store.getters[r]},n[o].vuex=!0})),n})),b=M((function(t,e){var n={};return w(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=$(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 w(t){return function(t){return Array.isArray(t)||o(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 M(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function $(t,e,n){return t._modulesNamespaceMap[n]}function C(t,e,n){var o=n?t.groupCollapsed:t.group;try{o.call(t,e)}catch(n){t.log(e)}}function E(t){try{t.groupEnd()}catch(e){t.log("—— log end ——")}}function O(){var t=new Date;return" @ "+j(t.getHours(),2)+":"+j(t.getMinutes(),2)+":"+j(t.getSeconds(),2)+"."+j(t.getMilliseconds(),3)}function j(t,e){return n="0",o=e-t.toString().length,new Array(o+1).join(n)+t;var n,o}return{Store:s,install:v,version:"3.6.2",mapState:g,mapMutations:y,mapGetters:_,mapActions:b,createNamespacedHelpers:function(t){return{mapState:g.bind(null,t),mapGetters:_.bind(null,t),mapMutations:y.bind(null,t),mapActions:b.bind(null,t)}},createLogger:function(t){void 0===t&&(t={});var n=t.collapsed;void 0===n&&(n=!0);var o=t.filter;void 0===o&&(o=function(t,e,n){return!0});var r=t.transformer;void 0===r&&(r=function(t){return t});var i=t.mutationTransformer;void 0===i&&(i=function(t){return t});var c=t.actionFilter;void 0===c&&(c=function(t,e){return!0});var a=t.actionTransformer;void 0===a&&(a=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=e(t.state);void 0!==f&&(s&&t.subscribe((function(t,c){var a=e(c);if(o(t,l,a)){var s=O(),u=i(t),h="mutation "+t.type+s;C(f,h,n),f.log("%c prev state","color: #9E9E9E; font-weight: bold",r(l)),f.log("%c mutation","color: #03A9F4; font-weight: bold",u),f.log("%c next state","color: #4CAF50; font-weight: bold",r(a)),E(f)}l=a})),u&&t.subscribeAction((function(t,e){if(c(t,e)){var o=O(),r=a(t),i="action "+t.type+o;C(f,i,n),f.log("%c action","color: #03A9F4; font-weight: bold",r),E(f)}})))}}}})); diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.mjs b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.mjs new file mode 100644 index 000000000..2140898f4 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/dist/vuex.mjs @@ -0,0 +1,26 @@ +import Vuex from '../dist/vuex.common.js' + +const { + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} = Vuex + +export { + Vuex as default, + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/package.json b/packages/vue-cli-plugin-uni/packages/vuex3/package.json new file mode 100644 index 000000000..e8a851ea7 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/package.json @@ -0,0 +1,96 @@ +{ + "name": "vuex", + "version": "3.6.2", + "description": "state management for Vue.js", + "main": "dist/vuex.common.js", + "exports": { + ".": { + "module": "./dist/vuex.esm.js", + "require": "./dist/vuex.common.js", + "import": "./dist/vuex.mjs" + }, + "./": "./" + }, + "module": "dist/vuex.esm.js", + "unpkg": "dist/vuex.js", + "jsdelivr": "dist/vuex.js", + "typings": "types/index.d.ts", + "sideEffects": false, + "files": [ + "dist", + "types/index.d.ts", + "types/helpers.d.ts", + "types/logger.d.ts", + "types/vue.d.ts" + ], + "scripts": { + "dev": "node examples/server.js", + "build": "npm run build:main && npm run build:logger", + "build:main": "node scripts/build-main.js", + "build:logger": "node scripts/build-logger.js", + "lint": "eslint src test", + "test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e && npm run test:esm", + "test:unit": "jest --testPathIgnorePatterns test/e2e", + "test:e2e": "start-server-and-test dev http://localhost:8080 \"jest --testPathIgnorePatterns test/unit\"", + "test:ssr": "cross-env VUE_ENV=server jest --testPathIgnorePatterns test/e2e", + "test:types": "tsc -p types/test", + "test:esm": "node test/esm/esm-test.js", + "coverage": "jest --testPathIgnorePatterns test/e2e --coverage", + "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", + "release": "node scripts/release.js", + "docs": "vuepress dev docs", + "docs:build": "vuepress build docs" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuejs/vuex.git" + }, + "author": "Evan You", + "license": "MIT", + "bugs": { + "url": "https://github.com/vuejs/vuex/issues" + }, + "homepage": "https://github.com/vuejs/vuex#readme", + "peerDependencies": { + "vue": "^2.0.0" + }, + "devDependencies": { + "@babel/core": "^7.12.10", + "@babel/preset-env": "^7.12.11", + "@rollup/plugin-buble": "^0.21.3", + "@rollup/plugin-commonjs": "^11.1.0", + "@rollup/plugin-node-resolve": "^7.1.3", + "@rollup/plugin-replace": "^2.3.2", + "@types/node": "^13.13.5", + "@vuepress/theme-vue": "^1.8.0", + "babel-jest": "^26.6.3", + "babel-loader": "^8.2.2", + "brotli": "^1.3.2", + "chalk": "^4.0.0", + "conventional-changelog-cli": "^2.1.1", + "cross-env": "^5.2.0", + "css-loader": "^2.1.0", + "enquirer": "^2.3.5", + "eslint": "^6.8.0", + "eslint-plugin-vue-libs": "^4.0.0", + "execa": "^5.0.0", + "express": "^4.17.1", + "jest": "^26.6.3", + "puppeteer": "^4.0.0", + "regenerator-runtime": "^0.13.5", + "rollup": "^2.38.0", + "rollup-plugin-terser": "^5.3.0", + "semver": "^7.3.2", + "start-server-and-test": "^1.11.7", + "todomvc-app-css": "^2.3.0", + "typescript": "^3.8.3", + "vue": "2.5.22", + "vue-loader": "15.2.1", + "vue-server-renderer": "2.5.22", + "vue-template-compiler": "2.5.22", + "vuepress": "^1.8.0", + "webpack": "^4.43.0", + "webpack-dev-middleware": "^3.7.2", + "webpack-hot-middleware": "^2.25.0" + } +} diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/types/helpers.d.ts b/packages/vue-cli-plugin-uni/packages/vuex3/types/helpers.d.ts new file mode 100644 index 000000000..2de5cf9e5 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/types/helpers.d.ts @@ -0,0 +1,86 @@ +import Vue from 'vue'; +import { Dispatch, Commit } from './index'; + +type Computed = () => any; +type InlineComputed = T extends (...args: any[]) => infer R ? () => R : never +type MutationMethod = (...args: any[]) => void; +type ActionMethod = (...args: any[]) => Promise; +type InlineMethod any> = T extends (fn: any, ...args: infer Args) => infer R ? (...args: Args) => R : never +type CustomVue = Vue & Record; + +interface Mapper { + (map: Key[]): { [K in Key]: R }; + >(map: Map): { [K in keyof Map]: R }; +} + +interface MapperWithNamespace { + (namespace: string, map: Key[]): { [K in Key]: R }; + >(namespace: string, map: Map): { [K in keyof Map]: R }; +} + +interface MapperForState { + any> = {}>( + map: Map + ): { [K in keyof Map]: InlineComputed }; +} + +interface MapperForStateWithNamespace { + any> = {}>( + namespace: string, + map: Map + ): { [K in keyof Map]: InlineComputed }; +} + +interface MapperForAction { + any>>( + map: Map + ): { [K in keyof Map]: InlineMethod }; +} + +interface MapperForActionWithNamespace { + any>>( + namespace: string, + map: Map + ): { [K in keyof Map]: InlineMethod }; +} + +interface MapperForMutation { + any>>( + map: Map + ): { [K in keyof Map]: InlineMethod }; +} + +interface MapperForMutationWithNamespace { + any>>( + namespace: string, + map: Map + ): { [K in keyof Map]: InlineMethod }; +} + + +interface NamespacedMappers { + mapState: Mapper & MapperForState; + mapMutations: Mapper & MapperForMutation; + mapGetters: Mapper; + mapActions: Mapper & MapperForAction; +} + +export declare const mapState: Mapper + & MapperWithNamespace + & MapperForState + & MapperForStateWithNamespace; + +export declare const mapMutations: Mapper + & MapperWithNamespace + & MapperForMutation + & MapperForMutationWithNamespace; + +export declare const mapGetters: Mapper + & MapperWithNamespace; + +export declare const mapActions: Mapper + & MapperWithNamespace + & MapperForAction + & MapperForActionWithNamespace; + +export declare function createNamespacedHelpers(namespace: string): NamespacedMappers; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/types/index.d.ts b/packages/vue-cli-plugin-uni/packages/vuex3/types/index.d.ts new file mode 100644 index 000000000..aeb69617f --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/types/index.d.ts @@ -0,0 +1,164 @@ +import _Vue, { WatchOptions } from "vue"; + +// augment typings of Vue.js +import "./vue"; + +import { mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers } from "./helpers"; +import createLogger from "./logger"; + +export * from "./helpers"; +export * from "./logger"; + +export declare class Store { + constructor(options: StoreOptions); + + readonly state: S; + readonly getters: any; + + replaceState(state: S): void; + + dispatch: Dispatch; + commit: Commit; + + subscribe

(fn: (mutation: P, state: S) => any, options?: SubscribeOptions): () => void; + subscribeAction

(fn: SubscribeActionOptions, options?: SubscribeOptions): () => void; + watch(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void; + + registerModule(path: string, module: Module, options?: ModuleOptions): void; + registerModule(path: string[], module: Module, options?: ModuleOptions): void; + + unregisterModule(path: string): void; + unregisterModule(path: string[]): void; + + hasModule(path: string): boolean; + hasModule(path: string[]): boolean; + + hotUpdate(options: { + actions?: ActionTree; + mutations?: MutationTree; + getters?: GetterTree; + modules?: ModuleTree; + }): void; +} + +export declare function install(Vue: typeof _Vue): void; + +export interface Dispatch { + (type: string, payload?: any, options?: DispatchOptions): Promise; +

(payloadWithType: P, options?: DispatchOptions): Promise; +} + +export interface Commit { + (type: string, payload?: any, options?: CommitOptions): void; +

(payloadWithType: P, options?: CommitOptions): void; +} + +export interface ActionContext { + dispatch: Dispatch; + commit: Commit; + state: S; + getters: any; + rootState: R; + rootGetters: any; +} + +export interface Payload { + type: string; +} + +export interface MutationPayload extends Payload { + payload: any; +} + +export interface ActionPayload extends Payload { + payload: any; +} + +export interface SubscribeOptions { + prepend?: boolean +} + +export type ActionSubscriber = (action: P, state: S) => any; +export type ActionErrorSubscriber = (action: P, state: S, error: Error) => any; + +export interface ActionSubscribersObject { + before?: ActionSubscriber; + after?: ActionSubscriber; + error?: ActionErrorSubscriber; +} + +export type SubscribeActionOptions = ActionSubscriber | ActionSubscribersObject; + +export interface DispatchOptions { + root?: boolean; +} + +export interface CommitOptions { + silent?: boolean; + root?: boolean; +} + +export interface StoreOptions { + state?: S | (() => S); + getters?: GetterTree; + actions?: ActionTree; + mutations?: MutationTree; + modules?: ModuleTree; + plugins?: Plugin[]; + strict?: boolean; + devtools?: boolean; +} + +export type ActionHandler = (this: Store, injectee: ActionContext, payload?: any) => any; +export interface ActionObject { + root?: boolean; + handler: ActionHandler; +} + +export type Getter = (state: S, getters: any, rootState: R, rootGetters: any) => any; +export type Action = ActionHandler | ActionObject; +export type Mutation = (state: S, payload?: any) => any; +export type Plugin = (store: Store) => any; + +export interface Module { + namespaced?: boolean; + state?: S | (() => S); + getters?: GetterTree; + actions?: ActionTree; + mutations?: MutationTree; + modules?: ModuleTree; +} + +export interface ModuleOptions { + preserveState?: boolean; +} + +export interface GetterTree { + [key: string]: Getter; +} + +export interface ActionTree { + [key: string]: Action; +} + +export interface MutationTree { + [key: string]: Mutation; +} + +export interface ModuleTree { + [key: string]: Module; +} + +export { createLogger } + +declare const _default: { + Store: typeof Store; + install: typeof install; + mapState: typeof mapState, + mapMutations: typeof mapMutations, + mapGetters: typeof mapGetters, + mapActions: typeof mapActions, + createNamespacedHelpers: typeof createNamespacedHelpers, + createLogger: typeof createLogger +}; +export default _default; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/types/logger.d.ts b/packages/vue-cli-plugin-uni/packages/vuex3/types/logger.d.ts new file mode 100644 index 000000000..b813a671b --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/types/logger.d.ts @@ -0,0 +1,20 @@ +import { Payload, Plugin } from "./index"; + +interface Logger extends Partial> { + log(message: string, color: string, payload: any): void; + log(message: string): void; +} + +export interface LoggerOption { + collapsed?: boolean; + filter?:

(mutation: P, stateBefore: S, stateAfter: S) => boolean; + transformer?: (state: S) => any; + mutationTransformer?:

(mutation: P) => any; + actionFilter?:

(action: P, state: S) => boolean; + actionTransformer?:

(action: P) => any; + logMutations?: boolean; + logActions?: boolean; + logger?: Logger; +} + +export default function createLogger(option?: LoggerOption): Plugin; diff --git a/packages/vue-cli-plugin-uni/packages/vuex3/types/vue.d.ts b/packages/vue-cli-plugin-uni/packages/vuex3/types/vue.d.ts new file mode 100644 index 000000000..302fc4eb6 --- /dev/null +++ b/packages/vue-cli-plugin-uni/packages/vuex3/types/vue.d.ts @@ -0,0 +1,18 @@ +/** + * Extends interfaces in Vue.js + */ + +import Vue, { ComponentOptions } from "vue"; +import { Store } from "./index"; + +declare module "vue/types/options" { + interface ComponentOptions { + store?: Store; + } +} + +declare module "vue/types/vue" { + interface Vue { + $store: Store; + } +} -- GitLab