vuex.cjs.js 42 KB

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