vuex.esm.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /**
  2. * vuex v2.3.0
  3. * (c) 2017 Evan You
  4. * @license MIT
  5. */
  6. var applyMixin = function (Vue) {
  7. var version = Number(Vue.version.split('.')[0]);
  8. if (version >= 2) {
  9. var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1;
  10. Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit });
  11. } else {
  12. // override init and inject vuex init procedure
  13. // for 1.x backwards compatibility.
  14. var _init = Vue.prototype._init;
  15. Vue.prototype._init = function (options) {
  16. if ( options === void 0 ) options = {};
  17. options.init = options.init
  18. ? [vuexInit].concat(options.init)
  19. : vuexInit;
  20. _init.call(this, options);
  21. };
  22. }
  23. /**
  24. * Vuex init hook, injected into each instances init hooks list.
  25. */
  26. function vuexInit () {
  27. var options = this.$options;
  28. // store injection
  29. if (options.store) {
  30. this.$store = options.store;
  31. } else if (options.parent && options.parent.$store) {
  32. this.$store = options.parent.$store;
  33. }
  34. }
  35. };
  36. var devtoolHook =
  37. typeof window !== 'undefined' &&
  38. window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
  39. function devtoolPlugin (store) {
  40. if (!devtoolHook) { return }
  41. store._devtoolHook = devtoolHook;
  42. devtoolHook.emit('vuex:init', store);
  43. devtoolHook.on('vuex:travel-to-state', function (targetState) {
  44. store.replaceState(targetState);
  45. });
  46. store.subscribe(function (mutation, state) {
  47. devtoolHook.emit('vuex:mutation', mutation, state);
  48. });
  49. }
  50. /**
  51. * Get the first item that pass the test
  52. * by second argument function
  53. *
  54. * @param {Array} list
  55. * @param {Function} f
  56. * @return {*}
  57. */
  58. /**
  59. * Deep copy the given object considering circular structure.
  60. * This function caches all nested objects and its copies.
  61. * If it detects circular structure, use cached copy to avoid infinite loop.
  62. *
  63. * @param {*} obj
  64. * @param {Array<Object>} cache
  65. * @return {*}
  66. */
  67. /**
  68. * forEach for object
  69. */
  70. function forEachValue (obj, fn) {
  71. Object.keys(obj).forEach(function (key) { return fn(obj[key], key); });
  72. }
  73. function isObject (obj) {
  74. return obj !== null && typeof obj === 'object'
  75. }
  76. function isPromise (val) {
  77. return val && typeof val.then === 'function'
  78. }
  79. function assert (condition, msg) {
  80. if (!condition) { throw new Error(("[vuex] " + msg)) }
  81. }
  82. var Module = function Module (rawModule, runtime) {
  83. this.runtime = runtime;
  84. this._children = Object.create(null);
  85. this._rawModule = rawModule;
  86. var rawState = rawModule.state;
  87. this.state = (typeof rawState === 'function' ? rawState() : rawState) || {};
  88. };
  89. var prototypeAccessors$1 = { namespaced: {} };
  90. prototypeAccessors$1.namespaced.get = function () {
  91. return !!this._rawModule.namespaced
  92. };
  93. Module.prototype.addChild = function addChild (key, module) {
  94. this._children[key] = module;
  95. };
  96. Module.prototype.removeChild = function removeChild (key) {
  97. delete this._children[key];
  98. };
  99. Module.prototype.getChild = function getChild (key) {
  100. return this._children[key]
  101. };
  102. Module.prototype.update = function update (rawModule) {
  103. this._rawModule.namespaced = rawModule.namespaced;
  104. if (rawModule.actions) {
  105. this._rawModule.actions = rawModule.actions;
  106. }
  107. if (rawModule.mutations) {
  108. this._rawModule.mutations = rawModule.mutations;
  109. }
  110. if (rawModule.getters) {
  111. this._rawModule.getters = rawModule.getters;
  112. }
  113. };
  114. Module.prototype.forEachChild = function forEachChild (fn) {
  115. forEachValue(this._children, fn);
  116. };
  117. Module.prototype.forEachGetter = function forEachGetter (fn) {
  118. if (this._rawModule.getters) {
  119. forEachValue(this._rawModule.getters, fn);
  120. }
  121. };
  122. Module.prototype.forEachAction = function forEachAction (fn) {
  123. if (this._rawModule.actions) {
  124. forEachValue(this._rawModule.actions, fn);
  125. }
  126. };
  127. Module.prototype.forEachMutation = function forEachMutation (fn) {
  128. if (this._rawModule.mutations) {
  129. forEachValue(this._rawModule.mutations, fn);
  130. }
  131. };
  132. Object.defineProperties( Module.prototype, prototypeAccessors$1 );
  133. var ModuleCollection = function ModuleCollection (rawRootModule) {
  134. var this$1 = this;
  135. // register root module (Vuex.Store options)
  136. this.root = new Module(rawRootModule, false);
  137. // register all nested modules
  138. if (rawRootModule.modules) {
  139. forEachValue(rawRootModule.modules, function (rawModule, key) {
  140. this$1.register([key], rawModule, false);
  141. });
  142. }
  143. };
  144. ModuleCollection.prototype.get = function get (path) {
  145. return path.reduce(function (module, key) {
  146. return module.getChild(key)
  147. }, this.root)
  148. };
  149. ModuleCollection.prototype.getNamespace = function getNamespace (path) {
  150. var module = this.root;
  151. return path.reduce(function (namespace, key) {
  152. module = module.getChild(key);
  153. return namespace + (module.namespaced ? key + '/' : '')
  154. }, '')
  155. };
  156. ModuleCollection.prototype.update = function update$1 (rawRootModule) {
  157. update(this.root, rawRootModule);
  158. };
  159. ModuleCollection.prototype.register = function register (path, rawModule, runtime) {
  160. var this$1 = this;
  161. if ( runtime === void 0 ) runtime = true;
  162. var parent = this.get(path.slice(0, -1));
  163. var newModule = new Module(rawModule, runtime);
  164. parent.addChild(path[path.length - 1], newModule);
  165. // register nested modules
  166. if (rawModule.modules) {
  167. forEachValue(rawModule.modules, function (rawChildModule, key) {
  168. this$1.register(path.concat(key), rawChildModule, runtime);
  169. });
  170. }
  171. };
  172. ModuleCollection.prototype.unregister = function unregister (path) {
  173. var parent = this.get(path.slice(0, -1));
  174. var key = path[path.length - 1];
  175. if (!parent.getChild(key).runtime) { return }
  176. parent.removeChild(key);
  177. };
  178. function update (targetModule, newModule) {
  179. // update target module
  180. targetModule.update(newModule);
  181. // update nested modules
  182. if (newModule.modules) {
  183. for (var key in newModule.modules) {
  184. if (!targetModule.getChild(key)) {
  185. console.warn(
  186. "[vuex] trying to add a new module '" + key + "' on hot reloading, " +
  187. 'manual reload is needed'
  188. );
  189. return
  190. }
  191. update(targetModule.getChild(key), newModule.modules[key]);
  192. }
  193. }
  194. }
  195. var Vue; // bind on install
  196. var Store = function Store (options) {
  197. var this$1 = this;
  198. if ( options === void 0 ) options = {};
  199. assert(Vue, "must call Vue.use(Vuex) before creating a store instance.");
  200. assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.");
  201. var state = options.state; if ( state === void 0 ) state = {};
  202. var plugins = options.plugins; if ( plugins === void 0 ) plugins = [];
  203. var strict = options.strict; if ( strict === void 0 ) strict = false;
  204. // store internal state
  205. this._committing = false;
  206. this._actions = Object.create(null);
  207. this._mutations = Object.create(null);
  208. this._wrappedGetters = Object.create(null);
  209. this._modules = new ModuleCollection(options);
  210. this._modulesNamespaceMap = Object.create(null);
  211. this._subscribers = [];
  212. this._watcherVM = new Vue();
  213. // bind commit and dispatch to self
  214. var store = this;
  215. var ref = this;
  216. var dispatch = ref.dispatch;
  217. var commit = ref.commit;
  218. this.dispatch = function boundDispatch (type, payload) {
  219. return dispatch.call(store, type, payload)
  220. };
  221. this.commit = function boundCommit (type, payload, options) {
  222. return commit.call(store, type, payload, options)
  223. };
  224. // strict mode
  225. this.strict = strict;
  226. // init root module.
  227. // this also recursively registers all sub-modules
  228. // and collects all module getters inside this._wrappedGetters
  229. installModule(this, state, [], this._modules.root);
  230. // initialize the store vm, which is responsible for the reactivity
  231. // (also registers _wrappedGetters as computed properties)
  232. resetStoreVM(this, state);
  233. // apply plugins
  234. plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); });
  235. };
  236. var prototypeAccessors = { state: {} };
  237. prototypeAccessors.state.get = function () {
  238. return this._vm._data.$$state
  239. };
  240. prototypeAccessors.state.set = function (v) {
  241. assert(false, "Use store.replaceState() to explicit replace store state.");
  242. };
  243. Store.prototype.commit = function commit (_type, _payload, _options) {
  244. var this$1 = this;
  245. // check object-style commit
  246. var ref = unifyObjectStyle(_type, _payload, _options);
  247. var type = ref.type;
  248. var payload = ref.payload;
  249. var options = ref.options;
  250. var mutation = { type: type, payload: payload };
  251. var entry = this._mutations[type];
  252. if (!entry) {
  253. console.error(("[vuex] unknown mutation type: " + type));
  254. return
  255. }
  256. this._withCommit(function () {
  257. entry.forEach(function commitIterator (handler) {
  258. handler(payload);
  259. });
  260. });
  261. this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); });
  262. if (options && options.silent) {
  263. console.warn(
  264. "[vuex] mutation type: " + type + ". Silent option has been removed. " +
  265. 'Use the filter functionality in the vue-devtools'
  266. );
  267. }
  268. };
  269. Store.prototype.dispatch = function dispatch (_type, _payload) {
  270. // check object-style dispatch
  271. var ref = unifyObjectStyle(_type, _payload);
  272. var type = ref.type;
  273. var payload = ref.payload;
  274. var entry = this._actions[type];
  275. if (!entry) {
  276. console.error(("[vuex] unknown action type: " + type));
  277. return
  278. }
  279. return entry.length > 1
  280. ? Promise.all(entry.map(function (handler) { return handler(payload); }))
  281. : entry[0](payload)
  282. };
  283. Store.prototype.subscribe = function subscribe (fn) {
  284. var subs = this._subscribers;
  285. if (subs.indexOf(fn) < 0) {
  286. subs.push(fn);
  287. }
  288. return function () {
  289. var i = subs.indexOf(fn);
  290. if (i > -1) {
  291. subs.splice(i, 1);
  292. }
  293. }
  294. };
  295. Store.prototype.watch = function watch (getter, cb, options) {
  296. var this$1 = this;
  297. assert(typeof getter === 'function', "store.watch only accepts a function.");
  298. return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options)
  299. };
  300. Store.prototype.replaceState = function replaceState (state) {
  301. var this$1 = this;
  302. this._withCommit(function () {
  303. this$1._vm._data.$$state = state;
  304. });
  305. };
  306. Store.prototype.registerModule = function registerModule (path, rawModule) {
  307. if (typeof path === 'string') { path = [path]; }
  308. assert(Array.isArray(path), "module path must be a string or an Array.");
  309. this._modules.register(path, rawModule);
  310. installModule(this, this.state, path, this._modules.get(path));
  311. // reset store to update getters...
  312. resetStoreVM(this, this.state);
  313. };
  314. Store.prototype.unregisterModule = function unregisterModule (path) {
  315. var this$1 = this;
  316. if (typeof path === 'string') { path = [path]; }
  317. assert(Array.isArray(path), "module path must be a string or an Array.");
  318. this._modules.unregister(path);
  319. this._withCommit(function () {
  320. var parentState = getNestedState(this$1.state, path.slice(0, -1));
  321. Vue.delete(parentState, path[path.length - 1]);
  322. });
  323. resetStore(this);
  324. };
  325. Store.prototype.hotUpdate = function hotUpdate (newOptions) {
  326. this._modules.update(newOptions);
  327. resetStore(this, true);
  328. };
  329. Store.prototype._withCommit = function _withCommit (fn) {
  330. var committing = this._committing;
  331. this._committing = true;
  332. fn();
  333. this._committing = committing;
  334. };
  335. Object.defineProperties( Store.prototype, prototypeAccessors );
  336. function resetStore (store, hot) {
  337. store._actions = Object.create(null);
  338. store._mutations = Object.create(null);
  339. store._wrappedGetters = Object.create(null);
  340. store._modulesNamespaceMap = Object.create(null);
  341. var state = store.state;
  342. // init all modules
  343. installModule(store, state, [], store._modules.root, true);
  344. // reset vm
  345. resetStoreVM(store, state, hot);
  346. }
  347. function resetStoreVM (store, state, hot) {
  348. var oldVm = store._vm;
  349. // bind store public getters
  350. store.getters = {};
  351. var wrappedGetters = store._wrappedGetters;
  352. var computed = {};
  353. forEachValue(wrappedGetters, function (fn, key) {
  354. // use computed to leverage its lazy-caching mechanism
  355. computed[key] = function () { return fn(store); };
  356. Object.defineProperty(store.getters, key, {
  357. get: function () { return store._vm[key]; },
  358. enumerable: true // for local getters
  359. });
  360. });
  361. // use a Vue instance to store the state tree
  362. // suppress warnings just in case the user has added
  363. // some funky global mixins
  364. var silent = Vue.config.silent;
  365. Vue.config.silent = true;
  366. store._vm = new Vue({
  367. data: {
  368. $$state: state
  369. },
  370. computed: computed
  371. });
  372. Vue.config.silent = silent;
  373. // enable strict mode for new vm
  374. if (store.strict) {
  375. enableStrictMode(store);
  376. }
  377. if (oldVm) {
  378. if (hot) {
  379. // dispatch changes in all subscribed watchers
  380. // to force getter re-evaluation for hot reloading.
  381. store._withCommit(function () {
  382. oldVm._data.$$state = null;
  383. });
  384. }
  385. Vue.nextTick(function () { return oldVm.$destroy(); });
  386. }
  387. }
  388. function installModule (store, rootState, path, module, hot) {
  389. var isRoot = !path.length;
  390. var namespace = store._modules.getNamespace(path);
  391. // register in namespace map
  392. if (module.namespaced) {
  393. store._modulesNamespaceMap[namespace] = module;
  394. }
  395. // set state
  396. if (!isRoot && !hot) {
  397. var parentState = getNestedState(rootState, path.slice(0, -1));
  398. var moduleName = path[path.length - 1];
  399. store._withCommit(function () {
  400. Vue.set(parentState, moduleName, module.state);
  401. });
  402. }
  403. var local = module.context = makeLocalContext(store, namespace, path);
  404. module.forEachMutation(function (mutation, key) {
  405. var namespacedType = namespace + key;
  406. registerMutation(store, namespacedType, mutation, local);
  407. });
  408. module.forEachAction(function (action, key) {
  409. var namespacedType = namespace + key;
  410. registerAction(store, namespacedType, action, local);
  411. });
  412. module.forEachGetter(function (getter, key) {
  413. var namespacedType = namespace + key;
  414. registerGetter(store, namespacedType, getter, local);
  415. });
  416. module.forEachChild(function (child, key) {
  417. installModule(store, rootState, path.concat(key), child, hot);
  418. });
  419. }
  420. /**
  421. * make localized dispatch, commit, getters and state
  422. * if there is no namespace, just use root ones
  423. */
  424. function makeLocalContext (store, namespace, path) {
  425. var noNamespace = namespace === '';
  426. var local = {
  427. dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) {
  428. var args = unifyObjectStyle(_type, _payload, _options);
  429. var payload = args.payload;
  430. var options = args.options;
  431. var type = args.type;
  432. if (!options || !options.root) {
  433. type = namespace + type;
  434. if (!store._actions[type]) {
  435. console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type));
  436. return
  437. }
  438. }
  439. return store.dispatch(type, payload)
  440. },
  441. commit: noNamespace ? store.commit : function (_type, _payload, _options) {
  442. var args = unifyObjectStyle(_type, _payload, _options);
  443. var payload = args.payload;
  444. var options = args.options;
  445. var type = args.type;
  446. if (!options || !options.root) {
  447. type = namespace + type;
  448. if (!store._mutations[type]) {
  449. console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type));
  450. return
  451. }
  452. }
  453. store.commit(type, payload, options);
  454. }
  455. };
  456. // getters and state object must be gotten lazily
  457. // because they will be changed by vm update
  458. Object.defineProperties(local, {
  459. getters: {
  460. get: noNamespace
  461. ? function () { return store.getters; }
  462. : function () { return makeLocalGetters(store, namespace); }
  463. },
  464. state: {
  465. get: function () { return getNestedState(store.state, path); }
  466. }
  467. });
  468. return local
  469. }
  470. function makeLocalGetters (store, namespace) {
  471. var gettersProxy = {};
  472. var splitPos = namespace.length;
  473. Object.keys(store.getters).forEach(function (type) {
  474. // skip if the target getter is not match this namespace
  475. if (type.slice(0, splitPos) !== namespace) { return }
  476. // extract local getter type
  477. var localType = type.slice(splitPos);
  478. // Add a port to the getters proxy.
  479. // Define as getter property because
  480. // we do not want to evaluate the getters in this time.
  481. Object.defineProperty(gettersProxy, localType, {
  482. get: function () { return store.getters[type]; },
  483. enumerable: true
  484. });
  485. });
  486. return gettersProxy
  487. }
  488. function registerMutation (store, type, handler, local) {
  489. var entry = store._mutations[type] || (store._mutations[type] = []);
  490. entry.push(function wrappedMutationHandler (payload) {
  491. handler(local.state, payload);
  492. });
  493. }
  494. function registerAction (store, type, handler, local) {
  495. var entry = store._actions[type] || (store._actions[type] = []);
  496. entry.push(function wrappedActionHandler (payload, cb) {
  497. var res = handler({
  498. dispatch: local.dispatch,
  499. commit: local.commit,
  500. getters: local.getters,
  501. state: local.state,
  502. rootGetters: store.getters,
  503. rootState: store.state
  504. }, payload, cb);
  505. if (!isPromise(res)) {
  506. res = Promise.resolve(res);
  507. }
  508. if (store._devtoolHook) {
  509. return res.catch(function (err) {
  510. store._devtoolHook.emit('vuex:error', err);
  511. throw err
  512. })
  513. } else {
  514. return res
  515. }
  516. });
  517. }
  518. function registerGetter (store, type, rawGetter, local) {
  519. if (store._wrappedGetters[type]) {
  520. console.error(("[vuex] duplicate getter key: " + type));
  521. return
  522. }
  523. store._wrappedGetters[type] = function wrappedGetter (store) {
  524. return rawGetter(
  525. local.state, // local state
  526. local.getters, // local getters
  527. store.state, // root state
  528. store.getters // root getters
  529. )
  530. };
  531. }
  532. function enableStrictMode (store) {
  533. store._vm.$watch(function () { return this._data.$$state }, function () {
  534. assert(store._committing, "Do not mutate vuex store state outside mutation handlers.");
  535. }, { deep: true, sync: true });
  536. }
  537. function getNestedState (state, path) {
  538. return path.length
  539. ? path.reduce(function (state, key) { return state[key]; }, state)
  540. : state
  541. }
  542. function unifyObjectStyle (type, payload, options) {
  543. if (isObject(type) && type.type) {
  544. options = payload;
  545. payload = type;
  546. type = type.type;
  547. }
  548. assert(typeof type === 'string', ("Expects string as the type, but found " + (typeof type) + "."));
  549. return { type: type, payload: payload, options: options }
  550. }
  551. function install (_Vue) {
  552. if (Vue) {
  553. console.error(
  554. '[vuex] already installed. Vue.use(Vuex) should be called only once.'
  555. );
  556. return
  557. }
  558. Vue = _Vue;
  559. applyMixin(Vue);
  560. }
  561. // auto install in dist mode
  562. if (typeof window !== 'undefined' && window.Vue) {
  563. install(window.Vue);
  564. }
  565. var mapState = normalizeNamespace(function (namespace, states) {
  566. var res = {};
  567. normalizeMap(states).forEach(function (ref) {
  568. var key = ref.key;
  569. var val = ref.val;
  570. res[key] = function mappedState () {
  571. var state = this.$store.state;
  572. var getters = this.$store.getters;
  573. if (namespace) {
  574. var module = getModuleByNamespace(this.$store, 'mapState', namespace);
  575. if (!module) {
  576. return
  577. }
  578. state = module.context.state;
  579. getters = module.context.getters;
  580. }
  581. return typeof val === 'function'
  582. ? val.call(this, state, getters)
  583. : state[val]
  584. };
  585. // mark vuex getter for devtools
  586. res[key].vuex = true;
  587. });
  588. return res
  589. });
  590. var mapMutations = normalizeNamespace(function (namespace, mutations) {
  591. var res = {};
  592. normalizeMap(mutations).forEach(function (ref) {
  593. var key = ref.key;
  594. var val = ref.val;
  595. val = namespace + val;
  596. res[key] = function mappedMutation () {
  597. var args = [], len = arguments.length;
  598. while ( len-- ) args[ len ] = arguments[ len ];
  599. if (namespace && !getModuleByNamespace(this.$store, 'mapMutations', namespace)) {
  600. return
  601. }
  602. return this.$store.commit.apply(this.$store, [val].concat(args))
  603. };
  604. });
  605. return res
  606. });
  607. var mapGetters = normalizeNamespace(function (namespace, getters) {
  608. var res = {};
  609. normalizeMap(getters).forEach(function (ref) {
  610. var key = ref.key;
  611. var val = ref.val;
  612. val = namespace + val;
  613. res[key] = function mappedGetter () {
  614. if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) {
  615. return
  616. }
  617. if (!(val in this.$store.getters)) {
  618. console.error(("[vuex] unknown getter: " + val));
  619. return
  620. }
  621. return this.$store.getters[val]
  622. };
  623. // mark vuex getter for devtools
  624. res[key].vuex = true;
  625. });
  626. return res
  627. });
  628. var mapActions = normalizeNamespace(function (namespace, actions) {
  629. var res = {};
  630. normalizeMap(actions).forEach(function (ref) {
  631. var key = ref.key;
  632. var val = ref.val;
  633. val = namespace + val;
  634. res[key] = function mappedAction () {
  635. var args = [], len = arguments.length;
  636. while ( len-- ) args[ len ] = arguments[ len ];
  637. if (namespace && !getModuleByNamespace(this.$store, 'mapActions', namespace)) {
  638. return
  639. }
  640. return this.$store.dispatch.apply(this.$store, [val].concat(args))
  641. };
  642. });
  643. return res
  644. });
  645. function normalizeMap (map) {
  646. return Array.isArray(map)
  647. ? map.map(function (key) { return ({ key: key, val: key }); })
  648. : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); })
  649. }
  650. function normalizeNamespace (fn) {
  651. return function (namespace, map) {
  652. if (typeof namespace !== 'string') {
  653. map = namespace;
  654. namespace = '';
  655. } else if (namespace.charAt(namespace.length - 1) !== '/') {
  656. namespace += '/';
  657. }
  658. return fn(namespace, map)
  659. }
  660. }
  661. function getModuleByNamespace (store, helper, namespace) {
  662. var module = store._modulesNamespaceMap[namespace];
  663. if (!module) {
  664. console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace));
  665. }
  666. return module
  667. }
  668. var index_esm = {
  669. Store: Store,
  670. install: install,
  671. version: '2.3.0',
  672. mapState: mapState,
  673. mapMutations: mapMutations,
  674. mapGetters: mapGetters,
  675. mapActions: mapActions
  676. };
  677. export { Store, mapState, mapMutations, mapGetters, mapActions };export default index_esm;