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