vuex.esm-bundler.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. /*!
  2. * vuex v4.0.2
  3. * (c) 2021 Evan You
  4. * @license MIT
  5. */
  6. import { inject, reactive, watch } from 'vue';
  7. import { setupDevtoolsPlugin } from '@vue/devtools-api';
  8. var storeKey = 'store';
  9. function useStore (key) {
  10. if ( key === void 0 ) key = null;
  11. return inject(key !== null ? key : storeKey)
  12. }
  13. /**
  14. * Get the first item that pass the test
  15. * by second argument function
  16. *
  17. * @param {Array} list
  18. * @param {Function} f
  19. * @return {*}
  20. */
  21. function find (list, f) {
  22. return list.filter(f)[0]
  23. }
  24. /**
  25. * Deep copy the given object considering circular structure.
  26. * This function caches all nested objects and its copies.
  27. * If it detects circular structure, use cached copy to avoid infinite loop.
  28. *
  29. * @param {*} obj
  30. * @param {Array<Object>} cache
  31. * @return {*}
  32. */
  33. function deepCopy (obj, cache) {
  34. if ( cache === void 0 ) cache = [];
  35. // just return if obj is immutable value
  36. if (obj === null || typeof obj !== 'object') {
  37. return obj
  38. }
  39. // if obj is hit, it is in circular structure
  40. var hit = find(cache, function (c) { return c.original === obj; });
  41. if (hit) {
  42. return hit.copy
  43. }
  44. var copy = Array.isArray(obj) ? [] : {};
  45. // put the copy into cache at first
  46. // because we want to refer it in recursive deepCopy
  47. cache.push({
  48. original: obj,
  49. copy: copy
  50. });
  51. Object.keys(obj).forEach(function (key) {
  52. copy[key] = deepCopy(obj[key], cache);
  53. });
  54. return copy
  55. }
  56. /**
  57. * forEach for object
  58. */
  59. function forEachValue (obj, fn) {
  60. Object.keys(obj).forEach(function (key) { return fn(obj[key], key); });
  61. }
  62. function isObject (obj) {
  63. return obj !== null && typeof obj === 'object'
  64. }
  65. function isPromise (val) {
  66. return val && typeof val.then === 'function'
  67. }
  68. function assert (condition, msg) {
  69. if (!condition) { throw new Error(("[vuex] " + msg)) }
  70. }
  71. function partial (fn, arg) {
  72. return function () {
  73. return fn(arg)
  74. }
  75. }
  76. function genericSubscribe (fn, subs, options) {
  77. if (subs.indexOf(fn) < 0) {
  78. options && options.prepend
  79. ? subs.unshift(fn)
  80. : subs.push(fn);
  81. }
  82. return function () {
  83. var i = subs.indexOf(fn);
  84. if (i > -1) {
  85. subs.splice(i, 1);
  86. }
  87. }
  88. }
  89. function resetStore (store, hot) {
  90. store._actions = Object.create(null);
  91. store._mutations = Object.create(null);
  92. store._wrappedGetters = Object.create(null);
  93. store._modulesNamespaceMap = Object.create(null);
  94. var state = store.state;
  95. // init all modules
  96. installModule(store, state, [], store._modules.root, true);
  97. // reset state
  98. resetStoreState(store, state, hot);
  99. }
  100. function resetStoreState (store, state, hot) {
  101. var oldState = store._state;
  102. // bind store public getters
  103. store.getters = {};
  104. // reset local getters cache
  105. store._makeLocalGettersCache = Object.create(null);
  106. var wrappedGetters = store._wrappedGetters;
  107. var computedObj = {};
  108. forEachValue(wrappedGetters, function (fn, key) {
  109. // use computed to leverage its lazy-caching mechanism
  110. // direct inline function use will lead to closure preserving oldState.
  111. // using partial to return function with only arguments preserved in closure environment.
  112. computedObj[key] = partial(fn, store);
  113. Object.defineProperty(store.getters, key, {
  114. // TODO: use `computed` when it's possible. at the moment we can't due to
  115. // https://github.com/vuejs/vuex/pull/1883
  116. get: function () { return computedObj[key](); },
  117. enumerable: true // for local getters
  118. });
  119. });
  120. store._state = reactive({
  121. data: state
  122. });
  123. // enable strict mode for new state
  124. if (store.strict) {
  125. enableStrictMode(store);
  126. }
  127. if (oldState) {
  128. if (hot) {
  129. // dispatch changes in all subscribed watchers
  130. // to force getter re-evaluation for hot reloading.
  131. store._withCommit(function () {
  132. oldState.data = null;
  133. });
  134. }
  135. }
  136. }
  137. function installModule (store, rootState, path, module, hot) {
  138. var isRoot = !path.length;
  139. var namespace = store._modules.getNamespace(path);
  140. // register in namespace map
  141. if (module.namespaced) {
  142. if (store._modulesNamespaceMap[namespace] && (process.env.NODE_ENV !== 'production')) {
  143. console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/'))));
  144. }
  145. store._modulesNamespaceMap[namespace] = module;
  146. }
  147. // set state
  148. if (!isRoot && !hot) {
  149. var parentState = getNestedState(rootState, path.slice(0, -1));
  150. var moduleName = path[path.length - 1];
  151. store._withCommit(function () {
  152. if ((process.env.NODE_ENV !== 'production')) {
  153. if (moduleName in parentState) {
  154. console.warn(
  155. ("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"")
  156. );
  157. }
  158. }
  159. parentState[moduleName] = module.state;
  160. });
  161. }
  162. var local = module.context = makeLocalContext(store, namespace, path);
  163. module.forEachMutation(function (mutation, key) {
  164. var namespacedType = namespace + key;
  165. registerMutation(store, namespacedType, mutation, local);
  166. });
  167. module.forEachAction(function (action, key) {
  168. var type = action.root ? key : namespace + key;
  169. var handler = action.handler || action;
  170. registerAction(store, type, handler, local);
  171. });
  172. module.forEachGetter(function (getter, key) {
  173. var namespacedType = namespace + key;
  174. registerGetter(store, namespacedType, getter, local);
  175. });
  176. module.forEachChild(function (child, key) {
  177. installModule(store, rootState, path.concat(key), child, hot);
  178. });
  179. }
  180. /**
  181. * make localized dispatch, commit, getters and state
  182. * if there is no namespace, just use root ones
  183. */
  184. function makeLocalContext (store, namespace, path) {
  185. var noNamespace = namespace === '';
  186. var local = {
  187. dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) {
  188. var args = unifyObjectStyle(_type, _payload, _options);
  189. var payload = args.payload;
  190. var options = args.options;
  191. var type = args.type;
  192. if (!options || !options.root) {
  193. type = namespace + type;
  194. if ((process.env.NODE_ENV !== 'production') && !store._actions[type]) {
  195. console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type));
  196. return
  197. }
  198. }
  199. return store.dispatch(type, payload)
  200. },
  201. commit: noNamespace ? store.commit : function (_type, _payload, _options) {
  202. var args = unifyObjectStyle(_type, _payload, _options);
  203. var payload = args.payload;
  204. var options = args.options;
  205. var type = args.type;
  206. if (!options || !options.root) {
  207. type = namespace + type;
  208. if ((process.env.NODE_ENV !== 'production') && !store._mutations[type]) {
  209. console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type));
  210. return
  211. }
  212. }
  213. store.commit(type, payload, options);
  214. }
  215. };
  216. // getters and state object must be gotten lazily
  217. // because they will be changed by state update
  218. Object.defineProperties(local, {
  219. getters: {
  220. get: noNamespace
  221. ? function () { return store.getters; }
  222. : function () { return makeLocalGetters(store, namespace); }
  223. },
  224. state: {
  225. get: function () { return getNestedState(store.state, path); }
  226. }
  227. });
  228. return local
  229. }
  230. function makeLocalGetters (store, namespace) {
  231. if (!store._makeLocalGettersCache[namespace]) {
  232. var gettersProxy = {};
  233. var splitPos = namespace.length;
  234. Object.keys(store.getters).forEach(function (type) {
  235. // skip if the target getter is not match this namespace
  236. if (type.slice(0, splitPos) !== namespace) { return }
  237. // extract local getter type
  238. var localType = type.slice(splitPos);
  239. // Add a port to the getters proxy.
  240. // Define as getter property because
  241. // we do not want to evaluate the getters in this time.
  242. Object.defineProperty(gettersProxy, localType, {
  243. get: function () { return store.getters[type]; },
  244. enumerable: true
  245. });
  246. });
  247. store._makeLocalGettersCache[namespace] = gettersProxy;
  248. }
  249. return store._makeLocalGettersCache[namespace]
  250. }
  251. function registerMutation (store, type, handler, local) {
  252. var entry = store._mutations[type] || (store._mutations[type] = []);
  253. entry.push(function wrappedMutationHandler (payload) {
  254. handler.call(store, local.state, payload);
  255. });
  256. }
  257. function registerAction (store, type, handler, local) {
  258. var entry = store._actions[type] || (store._actions[type] = []);
  259. entry.push(function wrappedActionHandler (payload) {
  260. var res = handler.call(store, {
  261. dispatch: local.dispatch,
  262. commit: local.commit,
  263. getters: local.getters,
  264. state: local.state,
  265. rootGetters: store.getters,
  266. rootState: store.state
  267. }, payload);
  268. if (!isPromise(res)) {
  269. res = Promise.resolve(res);
  270. }
  271. if (store._devtoolHook) {
  272. return res.catch(function (err) {
  273. store._devtoolHook.emit('vuex:error', err);
  274. throw err
  275. })
  276. } else {
  277. return res
  278. }
  279. });
  280. }
  281. function registerGetter (store, type, rawGetter, local) {
  282. if (store._wrappedGetters[type]) {
  283. if ((process.env.NODE_ENV !== 'production')) {
  284. console.error(("[vuex] duplicate getter key: " + type));
  285. }
  286. return
  287. }
  288. store._wrappedGetters[type] = function wrappedGetter (store) {
  289. return rawGetter(
  290. local.state, // local state
  291. local.getters, // local getters
  292. store.state, // root state
  293. store.getters // root getters
  294. )
  295. };
  296. }
  297. function enableStrictMode (store) {
  298. watch(function () { return store._state.data; }, function () {
  299. if ((process.env.NODE_ENV !== 'production')) {
  300. assert(store._committing, "do not mutate vuex store state outside mutation handlers.");
  301. }
  302. }, { deep: true, flush: 'sync' });
  303. }
  304. function getNestedState (state, path) {
  305. return path.reduce(function (state, key) { return state[key]; }, state)
  306. }
  307. function unifyObjectStyle (type, payload, options) {
  308. if (isObject(type) && type.type) {
  309. options = payload;
  310. payload = type;
  311. type = type.type;
  312. }
  313. if ((process.env.NODE_ENV !== 'production')) {
  314. assert(typeof type === 'string', ("expects string as the type, but found " + (typeof type) + "."));
  315. }
  316. return { type: type, payload: payload, options: options }
  317. }
  318. var LABEL_VUEX_BINDINGS = 'vuex bindings';
  319. var MUTATIONS_LAYER_ID = 'vuex:mutations';
  320. var ACTIONS_LAYER_ID = 'vuex:actions';
  321. var INSPECTOR_ID = 'vuex';
  322. var actionId = 0;
  323. function addDevtools (app, store) {
  324. setupDevtoolsPlugin(
  325. {
  326. id: 'org.vuejs.vuex',
  327. app: app,
  328. label: 'Vuex',
  329. homepage: 'https://next.vuex.vuejs.org/',
  330. logo: 'https://vuejs.org/images/icons/favicon-96x96.png',
  331. packageName: 'vuex',
  332. componentStateTypes: [LABEL_VUEX_BINDINGS]
  333. },
  334. function (api) {
  335. api.addTimelineLayer({
  336. id: MUTATIONS_LAYER_ID,
  337. label: 'Vuex Mutations',
  338. color: COLOR_LIME_500
  339. });
  340. api.addTimelineLayer({
  341. id: ACTIONS_LAYER_ID,
  342. label: 'Vuex Actions',
  343. color: COLOR_LIME_500
  344. });
  345. api.addInspector({
  346. id: INSPECTOR_ID,
  347. label: 'Vuex',
  348. icon: 'storage',
  349. treeFilterPlaceholder: 'Filter stores...'
  350. });
  351. api.on.getInspectorTree(function (payload) {
  352. if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
  353. if (payload.filter) {
  354. var nodes = [];
  355. flattenStoreForInspectorTree(nodes, store._modules.root, payload.filter, '');
  356. payload.rootNodes = nodes;
  357. } else {
  358. payload.rootNodes = [
  359. formatStoreForInspectorTree(store._modules.root, '')
  360. ];
  361. }
  362. }
  363. });
  364. api.on.getInspectorState(function (payload) {
  365. if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
  366. var modulePath = payload.nodeId;
  367. makeLocalGetters(store, modulePath);
  368. payload.state = formatStoreForInspectorState(
  369. getStoreModule(store._modules, modulePath),
  370. modulePath === 'root' ? store.getters : store._makeLocalGettersCache,
  371. modulePath
  372. );
  373. }
  374. });
  375. api.on.editInspectorState(function (payload) {
  376. if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
  377. var modulePath = payload.nodeId;
  378. var path = payload.path;
  379. if (modulePath !== 'root') {
  380. path = modulePath.split('/').filter(Boolean).concat( path);
  381. }
  382. store._withCommit(function () {
  383. payload.set(store._state.data, path, payload.state.value);
  384. });
  385. }
  386. });
  387. store.subscribe(function (mutation, state) {
  388. var data = {};
  389. if (mutation.payload) {
  390. data.payload = mutation.payload;
  391. }
  392. data.state = state;
  393. api.notifyComponentUpdate();
  394. api.sendInspectorTree(INSPECTOR_ID);
  395. api.sendInspectorState(INSPECTOR_ID);
  396. api.addTimelineEvent({
  397. layerId: MUTATIONS_LAYER_ID,
  398. event: {
  399. time: Date.now(),
  400. title: mutation.type,
  401. data: data
  402. }
  403. });
  404. });
  405. store.subscribeAction({
  406. before: function (action, state) {
  407. var data = {};
  408. if (action.payload) {
  409. data.payload = action.payload;
  410. }
  411. action._id = actionId++;
  412. action._time = Date.now();
  413. data.state = state;
  414. api.addTimelineEvent({
  415. layerId: ACTIONS_LAYER_ID,
  416. event: {
  417. time: action._time,
  418. title: action.type,
  419. groupId: action._id,
  420. subtitle: 'start',
  421. data: data
  422. }
  423. });
  424. },
  425. after: function (action, state) {
  426. var data = {};
  427. var duration = Date.now() - action._time;
  428. data.duration = {
  429. _custom: {
  430. type: 'duration',
  431. display: (duration + "ms"),
  432. tooltip: 'Action duration',
  433. value: duration
  434. }
  435. };
  436. if (action.payload) {
  437. data.payload = action.payload;
  438. }
  439. data.state = state;
  440. api.addTimelineEvent({
  441. layerId: ACTIONS_LAYER_ID,
  442. event: {
  443. time: Date.now(),
  444. title: action.type,
  445. groupId: action._id,
  446. subtitle: 'end',
  447. data: data
  448. }
  449. });
  450. }
  451. });
  452. }
  453. );
  454. }
  455. // extracted from tailwind palette
  456. var COLOR_LIME_500 = 0x84cc16;
  457. var COLOR_DARK = 0x666666;
  458. var COLOR_WHITE = 0xffffff;
  459. var TAG_NAMESPACED = {
  460. label: 'namespaced',
  461. textColor: COLOR_WHITE,
  462. backgroundColor: COLOR_DARK
  463. };
  464. /**
  465. * @param {string} path
  466. */
  467. function extractNameFromPath (path) {
  468. return path && path !== 'root' ? path.split('/').slice(-2, -1)[0] : 'Root'
  469. }
  470. /**
  471. * @param {*} module
  472. * @return {import('@vue/devtools-api').CustomInspectorNode}
  473. */
  474. function formatStoreForInspectorTree (module, path) {
  475. return {
  476. id: path || 'root',
  477. // all modules end with a `/`, we want the last segment only
  478. // cart/ -> cart
  479. // nested/cart/ -> cart
  480. label: extractNameFromPath(path),
  481. tags: module.namespaced ? [TAG_NAMESPACED] : [],
  482. children: Object.keys(module._children).map(function (moduleName) { return formatStoreForInspectorTree(
  483. module._children[moduleName],
  484. path + moduleName + '/'
  485. ); }
  486. )
  487. }
  488. }
  489. /**
  490. * @param {import('@vue/devtools-api').CustomInspectorNode[]} result
  491. * @param {*} module
  492. * @param {string} filter
  493. * @param {string} path
  494. */
  495. function flattenStoreForInspectorTree (result, module, filter, path) {
  496. if (path.includes(filter)) {
  497. result.push({
  498. id: path || 'root',
  499. label: path.endsWith('/') ? path.slice(0, path.length - 1) : path || 'Root',
  500. tags: module.namespaced ? [TAG_NAMESPACED] : []
  501. });
  502. }
  503. Object.keys(module._children).forEach(function (moduleName) {
  504. flattenStoreForInspectorTree(result, module._children[moduleName], filter, path + moduleName + '/');
  505. });
  506. }
  507. /**
  508. * @param {*} module
  509. * @return {import('@vue/devtools-api').CustomInspectorState}
  510. */
  511. function formatStoreForInspectorState (module, getters, path) {
  512. getters = path === 'root' ? getters : getters[path];
  513. var gettersKeys = Object.keys(getters);
  514. var storeState = {
  515. state: Object.keys(module.state).map(function (key) { return ({
  516. key: key,
  517. editable: true,
  518. value: module.state[key]
  519. }); })
  520. };
  521. if (gettersKeys.length) {
  522. var tree = transformPathsToObjectTree(getters);
  523. storeState.getters = Object.keys(tree).map(function (key) { return ({
  524. key: key.endsWith('/') ? extractNameFromPath(key) : key,
  525. editable: false,
  526. value: canThrow(function () { return tree[key]; })
  527. }); });
  528. }
  529. return storeState
  530. }
  531. function transformPathsToObjectTree (getters) {
  532. var result = {};
  533. Object.keys(getters).forEach(function (key) {
  534. var path = key.split('/');
  535. if (path.length > 1) {
  536. var target = result;
  537. var leafKey = path.pop();
  538. path.forEach(function (p) {
  539. if (!target[p]) {
  540. target[p] = {
  541. _custom: {
  542. value: {},
  543. display: p,
  544. tooltip: 'Module',
  545. abstract: true
  546. }
  547. };
  548. }
  549. target = target[p]._custom.value;
  550. });
  551. target[leafKey] = canThrow(function () { return getters[key]; });
  552. } else {
  553. result[key] = canThrow(function () { return getters[key]; });
  554. }
  555. });
  556. return result
  557. }
  558. function getStoreModule (moduleMap, path) {
  559. var names = path.split('/').filter(function (n) { return n; });
  560. return names.reduce(
  561. function (module, moduleName, i) {
  562. var child = module[moduleName];
  563. if (!child) {
  564. throw new Error(("Missing module \"" + moduleName + "\" for path \"" + path + "\"."))
  565. }
  566. return i === names.length - 1 ? child : child._children
  567. },
  568. path === 'root' ? moduleMap : moduleMap.root._children
  569. )
  570. }
  571. function canThrow (cb) {
  572. try {
  573. return cb()
  574. } catch (e) {
  575. return e
  576. }
  577. }
  578. // Base data struct for store's module, package with some attribute and method
  579. var Module = function Module (rawModule, runtime) {
  580. this.runtime = runtime;
  581. // Store some children item
  582. this._children = Object.create(null);
  583. // Store the origin module object which passed by programmer
  584. this._rawModule = rawModule;
  585. var rawState = rawModule.state;
  586. // Store the origin module's state
  587. this.state = (typeof rawState === 'function' ? rawState() : rawState) || {};
  588. };
  589. var prototypeAccessors$1 = { namespaced: { configurable: true } };
  590. prototypeAccessors$1.namespaced.get = function () {
  591. return !!this._rawModule.namespaced
  592. };
  593. Module.prototype.addChild = function addChild (key, module) {
  594. this._children[key] = module;
  595. };
  596. Module.prototype.removeChild = function removeChild (key) {
  597. delete this._children[key];
  598. };
  599. Module.prototype.getChild = function getChild (key) {
  600. return this._children[key]
  601. };
  602. Module.prototype.hasChild = function hasChild (key) {
  603. return key in this._children
  604. };
  605. Module.prototype.update = function update (rawModule) {
  606. this._rawModule.namespaced = rawModule.namespaced;
  607. if (rawModule.actions) {
  608. this._rawModule.actions = rawModule.actions;
  609. }
  610. if (rawModule.mutations) {
  611. this._rawModule.mutations = rawModule.mutations;
  612. }
  613. if (rawModule.getters) {
  614. this._rawModule.getters = rawModule.getters;
  615. }
  616. };
  617. Module.prototype.forEachChild = function forEachChild (fn) {
  618. forEachValue(this._children, fn);
  619. };
  620. Module.prototype.forEachGetter = function forEachGetter (fn) {
  621. if (this._rawModule.getters) {
  622. forEachValue(this._rawModule.getters, fn);
  623. }
  624. };
  625. Module.prototype.forEachAction = function forEachAction (fn) {
  626. if (this._rawModule.actions) {
  627. forEachValue(this._rawModule.actions, fn);
  628. }
  629. };
  630. Module.prototype.forEachMutation = function forEachMutation (fn) {
  631. if (this._rawModule.mutations) {
  632. forEachValue(this._rawModule.mutations, fn);
  633. }
  634. };
  635. Object.defineProperties( Module.prototype, prototypeAccessors$1 );
  636. var ModuleCollection = function ModuleCollection (rawRootModule) {
  637. // register root module (Vuex.Store options)
  638. this.register([], rawRootModule, false);
  639. };
  640. ModuleCollection.prototype.get = function get (path) {
  641. return path.reduce(function (module, key) {
  642. return module.getChild(key)
  643. }, this.root)
  644. };
  645. ModuleCollection.prototype.getNamespace = function getNamespace (path) {
  646. var module = this.root;
  647. return path.reduce(function (namespace, key) {
  648. module = module.getChild(key);
  649. return namespace + (module.namespaced ? key + '/' : '')
  650. }, '')
  651. };
  652. ModuleCollection.prototype.update = function update$1 (rawRootModule) {
  653. update([], this.root, rawRootModule);
  654. };
  655. ModuleCollection.prototype.register = function register (path, rawModule, runtime) {
  656. var this$1$1 = this;
  657. if ( runtime === void 0 ) runtime = true;
  658. if ((process.env.NODE_ENV !== 'production')) {
  659. assertRawModule(path, rawModule);
  660. }
  661. var newModule = new Module(rawModule, runtime);
  662. if (path.length === 0) {
  663. this.root = newModule;
  664. } else {
  665. var parent = this.get(path.slice(0, -1));
  666. parent.addChild(path[path.length - 1], newModule);
  667. }
  668. // register nested modules
  669. if (rawModule.modules) {
  670. forEachValue(rawModule.modules, function (rawChildModule, key) {
  671. this$1$1.register(path.concat(key), rawChildModule, runtime);
  672. });
  673. }
  674. };
  675. ModuleCollection.prototype.unregister = function unregister (path) {
  676. var parent = this.get(path.slice(0, -1));
  677. var key = path[path.length - 1];
  678. var child = parent.getChild(key);
  679. if (!child) {
  680. if ((process.env.NODE_ENV !== 'production')) {
  681. console.warn(
  682. "[vuex] trying to unregister module '" + key + "', which is " +
  683. "not registered"
  684. );
  685. }
  686. return
  687. }
  688. if (!child.runtime) {
  689. return
  690. }
  691. parent.removeChild(key);
  692. };
  693. ModuleCollection.prototype.isRegistered = function isRegistered (path) {
  694. var parent = this.get(path.slice(0, -1));
  695. var key = path[path.length - 1];
  696. if (parent) {
  697. return parent.hasChild(key)
  698. }
  699. return false
  700. };
  701. function update (path, targetModule, newModule) {
  702. if ((process.env.NODE_ENV !== 'production')) {
  703. assertRawModule(path, newModule);
  704. }
  705. // update target module
  706. targetModule.update(newModule);
  707. // update nested modules
  708. if (newModule.modules) {
  709. for (var key in newModule.modules) {
  710. if (!targetModule.getChild(key)) {
  711. if ((process.env.NODE_ENV !== 'production')) {
  712. console.warn(
  713. "[vuex] trying to add a new module '" + key + "' on hot reloading, " +
  714. 'manual reload is needed'
  715. );
  716. }
  717. return
  718. }
  719. update(
  720. path.concat(key),
  721. targetModule.getChild(key),
  722. newModule.modules[key]
  723. );
  724. }
  725. }
  726. }
  727. var functionAssert = {
  728. assert: function (value) { return typeof value === 'function'; },
  729. expected: 'function'
  730. };
  731. var objectAssert = {
  732. assert: function (value) { return typeof value === 'function' ||
  733. (typeof value === 'object' && typeof value.handler === 'function'); },
  734. expected: 'function or object with "handler" function'
  735. };
  736. var assertTypes = {
  737. getters: functionAssert,
  738. mutations: functionAssert,
  739. actions: objectAssert
  740. };
  741. function assertRawModule (path, rawModule) {
  742. Object.keys(assertTypes).forEach(function (key) {
  743. if (!rawModule[key]) { return }
  744. var assertOptions = assertTypes[key];
  745. forEachValue(rawModule[key], function (value, type) {
  746. assert(
  747. assertOptions.assert(value),
  748. makeAssertionMessage(path, key, type, value, assertOptions.expected)
  749. );
  750. });
  751. });
  752. }
  753. function makeAssertionMessage (path, key, type, value, expected) {
  754. var buf = key + " should be " + expected + " but \"" + key + "." + type + "\"";
  755. if (path.length > 0) {
  756. buf += " in module \"" + (path.join('.')) + "\"";
  757. }
  758. buf += " is " + (JSON.stringify(value)) + ".";
  759. return buf
  760. }
  761. function createStore (options) {
  762. return new Store(options)
  763. }
  764. var Store = function Store (options) {
  765. var this$1$1 = this;
  766. if ( options === void 0 ) options = {};
  767. if ((process.env.NODE_ENV !== 'production')) {
  768. assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.");
  769. assert(this instanceof Store, "store must be called with the new operator.");
  770. }
  771. var plugins = options.plugins; if ( plugins === void 0 ) plugins = [];
  772. var strict = options.strict; if ( strict === void 0 ) strict = false;
  773. var devtools = options.devtools;
  774. // store internal state
  775. this._committing = false;
  776. this._actions = Object.create(null);
  777. this._actionSubscribers = [];
  778. this._mutations = Object.create(null);
  779. this._wrappedGetters = Object.create(null);
  780. this._modules = new ModuleCollection(options);
  781. this._modulesNamespaceMap = Object.create(null);
  782. this._subscribers = [];
  783. this._makeLocalGettersCache = Object.create(null);
  784. this._devtools = devtools;
  785. // bind commit and dispatch to self
  786. var store = this;
  787. var ref = this;
  788. var dispatch = ref.dispatch;
  789. var commit = ref.commit;
  790. this.dispatch = function boundDispatch (type, payload) {
  791. return dispatch.call(store, type, payload)
  792. };
  793. this.commit = function boundCommit (type, payload, options) {
  794. return commit.call(store, type, payload, options)
  795. };
  796. // strict mode
  797. this.strict = strict;
  798. var state = this._modules.root.state;
  799. // init root module.
  800. // this also recursively registers all sub-modules
  801. // and collects all module getters inside this._wrappedGetters
  802. installModule(this, state, [], this._modules.root);
  803. // initialize the store state, which is responsible for the reactivity
  804. // (also registers _wrappedGetters as computed properties)
  805. resetStoreState(this, state);
  806. // apply plugins
  807. plugins.forEach(function (plugin) { return plugin(this$1$1); });
  808. };
  809. var prototypeAccessors = { state: { configurable: true } };
  810. Store.prototype.install = function install (app, injectKey) {
  811. app.provide(injectKey || storeKey, this);
  812. app.config.globalProperties.$store = this;
  813. var useDevtools = this._devtools !== undefined
  814. ? this._devtools
  815. : (process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__;
  816. if (useDevtools) {
  817. addDevtools(app, this);
  818. }
  819. };
  820. prototypeAccessors.state.get = function () {
  821. return this._state.data
  822. };
  823. prototypeAccessors.state.set = function (v) {
  824. if ((process.env.NODE_ENV !== 'production')) {
  825. assert(false, "use store.replaceState() to explicit replace store state.");
  826. }
  827. };
  828. Store.prototype.commit = function commit (_type, _payload, _options) {
  829. var this$1$1 = this;
  830. // check object-style commit
  831. var ref = unifyObjectStyle(_type, _payload, _options);
  832. var type = ref.type;
  833. var payload = ref.payload;
  834. var options = ref.options;
  835. var mutation = { type: type, payload: payload };
  836. var entry = this._mutations[type];
  837. if (!entry) {
  838. if ((process.env.NODE_ENV !== 'production')) {
  839. console.error(("[vuex] unknown mutation type: " + type));
  840. }
  841. return
  842. }
  843. this._withCommit(function () {
  844. entry.forEach(function commitIterator (handler) {
  845. handler(payload);
  846. });
  847. });
  848. this._subscribers
  849. .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe
  850. .forEach(function (sub) { return sub(mutation, this$1$1.state); });
  851. if (
  852. (process.env.NODE_ENV !== 'production') &&
  853. options && options.silent
  854. ) {
  855. console.warn(
  856. "[vuex] mutation type: " + type + ". Silent option has been removed. " +
  857. 'Use the filter functionality in the vue-devtools'
  858. );
  859. }
  860. };
  861. Store.prototype.dispatch = function dispatch (_type, _payload) {
  862. var this$1$1 = this;
  863. // check object-style dispatch
  864. var ref = unifyObjectStyle(_type, _payload);
  865. var type = ref.type;
  866. var payload = ref.payload;
  867. var action = { type: type, payload: payload };
  868. var entry = this._actions[type];
  869. if (!entry) {
  870. if ((process.env.NODE_ENV !== 'production')) {
  871. console.error(("[vuex] unknown action type: " + type));
  872. }
  873. return
  874. }
  875. try {
  876. this._actionSubscribers
  877. .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe
  878. .filter(function (sub) { return sub.before; })
  879. .forEach(function (sub) { return sub.before(action, this$1$1.state); });
  880. } catch (e) {
  881. if ((process.env.NODE_ENV !== 'production')) {
  882. console.warn("[vuex] error in before action subscribers: ");
  883. console.error(e);
  884. }
  885. }
  886. var result = entry.length > 1
  887. ? Promise.all(entry.map(function (handler) { return handler(payload); }))
  888. : entry[0](payload);
  889. return new Promise(function (resolve, reject) {
  890. result.then(function (res) {
  891. try {
  892. this$1$1._actionSubscribers
  893. .filter(function (sub) { return sub.after; })
  894. .forEach(function (sub) { return sub.after(action, this$1$1.state); });
  895. } catch (e) {
  896. if ((process.env.NODE_ENV !== 'production')) {
  897. console.warn("[vuex] error in after action subscribers: ");
  898. console.error(e);
  899. }
  900. }
  901. resolve(res);
  902. }, function (error) {
  903. try {
  904. this$1$1._actionSubscribers
  905. .filter(function (sub) { return sub.error; })
  906. .forEach(function (sub) { return sub.error(action, this$1$1.state, error); });
  907. } catch (e) {
  908. if ((process.env.NODE_ENV !== 'production')) {
  909. console.warn("[vuex] error in error action subscribers: ");
  910. console.error(e);
  911. }
  912. }
  913. reject(error);
  914. });
  915. })
  916. };
  917. Store.prototype.subscribe = function subscribe (fn, options) {
  918. return genericSubscribe(fn, this._subscribers, options)
  919. };
  920. Store.prototype.subscribeAction = function subscribeAction (fn, options) {
  921. var subs = typeof fn === 'function' ? { before: fn } : fn;
  922. return genericSubscribe(subs, this._actionSubscribers, options)
  923. };
  924. Store.prototype.watch = function watch$1 (getter, cb, options) {
  925. var this$1$1 = this;
  926. if ((process.env.NODE_ENV !== 'production')) {
  927. assert(typeof getter === 'function', "store.watch only accepts a function.");
  928. }
  929. return watch(function () { return getter(this$1$1.state, this$1$1.getters); }, cb, Object.assign({}, options))
  930. };
  931. Store.prototype.replaceState = function replaceState (state) {
  932. var this$1$1 = this;
  933. this._withCommit(function () {
  934. this$1$1._state.data = state;
  935. });
  936. };
  937. Store.prototype.registerModule = function registerModule (path, rawModule, options) {
  938. if ( options === void 0 ) options = {};
  939. if (typeof path === 'string') { path = [path]; }
  940. if ((process.env.NODE_ENV !== 'production')) {
  941. assert(Array.isArray(path), "module path must be a string or an Array.");
  942. assert(path.length > 0, 'cannot register the root module by using registerModule.');
  943. }
  944. this._modules.register(path, rawModule);
  945. installModule(this, this.state, path, this._modules.get(path), options.preserveState);
  946. // reset store to update getters...
  947. resetStoreState(this, this.state);
  948. };
  949. Store.prototype.unregisterModule = function unregisterModule (path) {
  950. var this$1$1 = this;
  951. if (typeof path === 'string') { path = [path]; }
  952. if ((process.env.NODE_ENV !== 'production')) {
  953. assert(Array.isArray(path), "module path must be a string or an Array.");
  954. }
  955. this._modules.unregister(path);
  956. this._withCommit(function () {
  957. var parentState = getNestedState(this$1$1.state, path.slice(0, -1));
  958. delete parentState[path[path.length - 1]];
  959. });
  960. resetStore(this);
  961. };
  962. Store.prototype.hasModule = function hasModule (path) {
  963. if (typeof path === 'string') { path = [path]; }
  964. if ((process.env.NODE_ENV !== 'production')) {
  965. assert(Array.isArray(path), "module path must be a string or an Array.");
  966. }
  967. return this._modules.isRegistered(path)
  968. };
  969. Store.prototype.hotUpdate = function hotUpdate (newOptions) {
  970. this._modules.update(newOptions);
  971. resetStore(this, true);
  972. };
  973. Store.prototype._withCommit = function _withCommit (fn) {
  974. var committing = this._committing;
  975. this._committing = true;
  976. fn();
  977. this._committing = committing;
  978. };
  979. Object.defineProperties( Store.prototype, prototypeAccessors );
  980. /**
  981. * Reduce the code which written in Vue.js for getting the state.
  982. * @param {String} [namespace] - Module's namespace
  983. * @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.
  984. * @param {Object}
  985. */
  986. var mapState = normalizeNamespace(function (namespace, states) {
  987. var res = {};
  988. if ((process.env.NODE_ENV !== 'production') && !isValidMap(states)) {
  989. console.error('[vuex] mapState: mapper parameter must be either an Array or an Object');
  990. }
  991. normalizeMap(states).forEach(function (ref) {
  992. var key = ref.key;
  993. var val = ref.val;
  994. res[key] = function mappedState () {
  995. var state = this.$store.state;
  996. var getters = this.$store.getters;
  997. if (namespace) {
  998. var module = getModuleByNamespace(this.$store, 'mapState', namespace);
  999. if (!module) {
  1000. return
  1001. }
  1002. state = module.context.state;
  1003. getters = module.context.getters;
  1004. }
  1005. return typeof val === 'function'
  1006. ? val.call(this, state, getters)
  1007. : state[val]
  1008. };
  1009. // mark vuex getter for devtools
  1010. res[key].vuex = true;
  1011. });
  1012. return res
  1013. });
  1014. /**
  1015. * Reduce the code which written in Vue.js for committing the mutation
  1016. * @param {String} [namespace] - Module's namespace
  1017. * @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.
  1018. * @return {Object}
  1019. */
  1020. var mapMutations = normalizeNamespace(function (namespace, mutations) {
  1021. var res = {};
  1022. if ((process.env.NODE_ENV !== 'production') && !isValidMap(mutations)) {
  1023. console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object');
  1024. }
  1025. normalizeMap(mutations).forEach(function (ref) {
  1026. var key = ref.key;
  1027. var val = ref.val;
  1028. res[key] = function mappedMutation () {
  1029. var args = [], len = arguments.length;
  1030. while ( len-- ) args[ len ] = arguments[ len ];
  1031. // Get the commit method from store
  1032. var commit = this.$store.commit;
  1033. if (namespace) {
  1034. var module = getModuleByNamespace(this.$store, 'mapMutations', namespace);
  1035. if (!module) {
  1036. return
  1037. }
  1038. commit = module.context.commit;
  1039. }
  1040. return typeof val === 'function'
  1041. ? val.apply(this, [commit].concat(args))
  1042. : commit.apply(this.$store, [val].concat(args))
  1043. };
  1044. });
  1045. return res
  1046. });
  1047. /**
  1048. * Reduce the code which written in Vue.js for getting the getters
  1049. * @param {String} [namespace] - Module's namespace
  1050. * @param {Object|Array} getters
  1051. * @return {Object}
  1052. */
  1053. var mapGetters = normalizeNamespace(function (namespace, getters) {
  1054. var res = {};
  1055. if ((process.env.NODE_ENV !== 'production') && !isValidMap(getters)) {
  1056. console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object');
  1057. }
  1058. normalizeMap(getters).forEach(function (ref) {
  1059. var key = ref.key;
  1060. var val = ref.val;
  1061. // The namespace has been mutated by normalizeNamespace
  1062. val = namespace + val;
  1063. res[key] = function mappedGetter () {
  1064. if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) {
  1065. return
  1066. }
  1067. if ((process.env.NODE_ENV !== 'production') && !(val in this.$store.getters)) {
  1068. console.error(("[vuex] unknown getter: " + val));
  1069. return
  1070. }
  1071. return this.$store.getters[val]
  1072. };
  1073. // mark vuex getter for devtools
  1074. res[key].vuex = true;
  1075. });
  1076. return res
  1077. });
  1078. /**
  1079. * Reduce the code which written in Vue.js for dispatch the action
  1080. * @param {String} [namespace] - Module's namespace
  1081. * @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.
  1082. * @return {Object}
  1083. */
  1084. var mapActions = normalizeNamespace(function (namespace, actions) {
  1085. var res = {};
  1086. if ((process.env.NODE_ENV !== 'production') && !isValidMap(actions)) {
  1087. console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object');
  1088. }
  1089. normalizeMap(actions).forEach(function (ref) {
  1090. var key = ref.key;
  1091. var val = ref.val;
  1092. res[key] = function mappedAction () {
  1093. var args = [], len = arguments.length;
  1094. while ( len-- ) args[ len ] = arguments[ len ];
  1095. // get dispatch function from store
  1096. var dispatch = this.$store.dispatch;
  1097. if (namespace) {
  1098. var module = getModuleByNamespace(this.$store, 'mapActions', namespace);
  1099. if (!module) {
  1100. return
  1101. }
  1102. dispatch = module.context.dispatch;
  1103. }
  1104. return typeof val === 'function'
  1105. ? val.apply(this, [dispatch].concat(args))
  1106. : dispatch.apply(this.$store, [val].concat(args))
  1107. };
  1108. });
  1109. return res
  1110. });
  1111. /**
  1112. * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object
  1113. * @param {String} namespace
  1114. * @return {Object}
  1115. */
  1116. var createNamespacedHelpers = function (namespace) { return ({
  1117. mapState: mapState.bind(null, namespace),
  1118. mapGetters: mapGetters.bind(null, namespace),
  1119. mapMutations: mapMutations.bind(null, namespace),
  1120. mapActions: mapActions.bind(null, namespace)
  1121. }); };
  1122. /**
  1123. * Normalize the map
  1124. * normalizeMap([1, 2, 3]) => [ { key: 1, val: 1 }, { key: 2, val: 2 }, { key: 3, val: 3 } ]
  1125. * normalizeMap({a: 1, b: 2, c: 3}) => [ { key: 'a', val: 1 }, { key: 'b', val: 2 }, { key: 'c', val: 3 } ]
  1126. * @param {Array|Object} map
  1127. * @return {Object}
  1128. */
  1129. function normalizeMap (map) {
  1130. if (!isValidMap(map)) {
  1131. return []
  1132. }
  1133. return Array.isArray(map)
  1134. ? map.map(function (key) { return ({ key: key, val: key }); })
  1135. : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); })
  1136. }
  1137. /**
  1138. * Validate whether given map is valid or not
  1139. * @param {*} map
  1140. * @return {Boolean}
  1141. */
  1142. function isValidMap (map) {
  1143. return Array.isArray(map) || isObject(map)
  1144. }
  1145. /**
  1146. * 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.
  1147. * @param {Function} fn
  1148. * @return {Function}
  1149. */
  1150. function normalizeNamespace (fn) {
  1151. return function (namespace, map) {
  1152. if (typeof namespace !== 'string') {
  1153. map = namespace;
  1154. namespace = '';
  1155. } else if (namespace.charAt(namespace.length - 1) !== '/') {
  1156. namespace += '/';
  1157. }
  1158. return fn(namespace, map)
  1159. }
  1160. }
  1161. /**
  1162. * Search a special module from store by namespace. if module not exist, print error message.
  1163. * @param {Object} store
  1164. * @param {String} helper
  1165. * @param {String} namespace
  1166. * @return {Object}
  1167. */
  1168. function getModuleByNamespace (store, helper, namespace) {
  1169. var module = store._modulesNamespaceMap[namespace];
  1170. if ((process.env.NODE_ENV !== 'production') && !module) {
  1171. console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace));
  1172. }
  1173. return module
  1174. }
  1175. // Credits: borrowed code from fcomb/redux-logger
  1176. function createLogger (ref) {
  1177. if ( ref === void 0 ) ref = {};
  1178. var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true;
  1179. var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return true; };
  1180. var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; };
  1181. var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; };
  1182. var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; };
  1183. var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; };
  1184. var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true;
  1185. var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true;
  1186. var logger = ref.logger; if ( logger === void 0 ) logger = console;
  1187. return function (store) {
  1188. var prevState = deepCopy(store.state);
  1189. if (typeof logger === 'undefined') {
  1190. return
  1191. }
  1192. if (logMutations) {
  1193. store.subscribe(function (mutation, state) {
  1194. var nextState = deepCopy(state);
  1195. if (filter(mutation, prevState, nextState)) {
  1196. var formattedTime = getFormattedTime();
  1197. var formattedMutation = mutationTransformer(mutation);
  1198. var message = "mutation " + (mutation.type) + formattedTime;
  1199. startMessage(logger, message, collapsed);
  1200. logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState));
  1201. logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation);
  1202. logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState));
  1203. endMessage(logger);
  1204. }
  1205. prevState = nextState;
  1206. });
  1207. }
  1208. if (logActions) {
  1209. store.subscribeAction(function (action, state) {
  1210. if (actionFilter(action, state)) {
  1211. var formattedTime = getFormattedTime();
  1212. var formattedAction = actionTransformer(action);
  1213. var message = "action " + (action.type) + formattedTime;
  1214. startMessage(logger, message, collapsed);
  1215. logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction);
  1216. endMessage(logger);
  1217. }
  1218. });
  1219. }
  1220. }
  1221. }
  1222. function startMessage (logger, message, collapsed) {
  1223. var startMessage = collapsed
  1224. ? logger.groupCollapsed
  1225. : logger.group;
  1226. // render
  1227. try {
  1228. startMessage.call(logger, message);
  1229. } catch (e) {
  1230. logger.log(message);
  1231. }
  1232. }
  1233. function endMessage (logger) {
  1234. try {
  1235. logger.groupEnd();
  1236. } catch (e) {
  1237. logger.log('—— log end ——');
  1238. }
  1239. }
  1240. function getFormattedTime () {
  1241. var time = new Date();
  1242. return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3)))
  1243. }
  1244. function repeat (str, times) {
  1245. return (new Array(times + 1)).join(str)
  1246. }
  1247. function pad (num, maxLength) {
  1248. return repeat('0', maxLength - num.toString().length) + num
  1249. }
  1250. var index = {
  1251. version: '4.0.2',
  1252. Store: Store,
  1253. storeKey: storeKey,
  1254. createStore: createStore,
  1255. useStore: useStore,
  1256. mapState: mapState,
  1257. mapMutations: mapMutations,
  1258. mapGetters: mapGetters,
  1259. mapActions: mapActions,
  1260. createNamespacedHelpers: createNamespacedHelpers,
  1261. createLogger: createLogger
  1262. };
  1263. export default index;
  1264. export { Store, createLogger, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, storeKey, useStore };