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