Node-Red configuration
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

vuex.global.js 45KB

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