vuex.global.js 44 KB

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