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