Node-Red configuration
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

vuex.cjs.js 43KB

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