项目原始demo,不改动
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
Este repositorio está archivado. Puede ver los archivos y clonarlo, pero no puede subir cambios o reportar incidencias ni pedir Pull Requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /**
  2. * vuex v3.0.1
  3. * (c) 2017 Evan You
  4. * @license MIT
  5. */
  6. 'use strict';
  7. var applyMixin = function (Vue) {
  8. var version = Number(Vue.version.split('.')[0]);
  9. if (version >= 2) {
  10. Vue.mixin({ beforeCreate: vuexInit });
  11. } else {
  12. // override init and inject vuex init procedure
  13. // for 1.x backwards compatibility.
  14. var _init = Vue.prototype._init;
  15. Vue.prototype._init = function (options) {
  16. if ( options === void 0 ) options = {};
  17. options.init = options.init
  18. ? [vuexInit].concat(options.init)
  19. : vuexInit;
  20. _init.call(this, options);
  21. };
  22. }
  23. /**
  24. * Vuex init hook, injected into each instances init hooks list.
  25. */
  26. function vuexInit () {
  27. var options = this.$options;
  28. // store injection
  29. if (options.store) {
  30. this.$store = typeof options.store === 'function'
  31. ? options.store()
  32. : options.store;
  33. } else if (options.parent && options.parent.$store) {
  34. this.$store = options.parent.$store;
  35. }
  36. }
  37. };
  38. var devtoolHook =
  39. typeof window !== 'undefined' &&
  40. window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
  41. function devtoolPlugin (store) {
  42. if (!devtoolHook) { return }
  43. store._devtoolHook = devtoolHook;
  44. devtoolHook.emit('vuex:init', store);
  45. devtoolHook.on('vuex:travel-to-state', function (targetState) {
  46. store.replaceState(targetState);
  47. });
  48. store.subscribe(function (mutation, state) {
  49. devtoolHook.emit('vuex:mutation', mutation, state);
  50. });
  51. }
  52. /**
  53. * Get the first item that pass the test
  54. * by second argument function
  55. *
  56. * @param {Array} list
  57. * @param {Function} f
  58. * @return {*}
  59. */
  60. /**
  61. * Deep copy the given object considering circular structure.
  62. * This function caches all nested objects and its copies.
  63. * If it detects circular structure, use cached copy to avoid infinite loop.
  64. *
  65. * @param {*} obj
  66. * @param {Array<Object>} cache
  67. * @return {*}
  68. */
  69. /**
  70. * forEach for object
  71. */
  72. function forEachValue (obj, fn) {
  73. Object.keys(obj).forEach(function (key) { return fn(obj[key], key); });
  74. }
  75. function isObject (obj) {
  76. return obj !== null && typeof obj === 'object'
  77. }
  78. function isPromise (val) {
  79. return val && typeof val.then === 'function'
  80. }
  81. function assert (condition, msg) {
  82. if (!condition) { throw new Error(("[vuex] " + msg)) }
  83. }
  84. var Module = function Module (rawModule, runtime) {
  85. this.runtime = runtime;
  86. this._children = Object.create(null);
  87. this._rawModule = rawModule;
  88. var rawState = rawModule.state;
  89. this.state = (typeof rawState === 'function' ? rawState() : rawState) || {};
  90. };
  91. var prototypeAccessors$1 = { namespaced: { configurable: true } };
  92. prototypeAccessors$1.namespaced.get = function () {
  93. return !!this._rawModule.namespaced
  94. };
  95. Module.prototype.addChild = function addChild (key, module) {
  96. this._children[key] = module;
  97. };
  98. Module.prototype.removeChild = function removeChild (key) {
  99. delete this._children[key];
  100. };
  101. Module.prototype.getChild = function getChild (key) {
  102. return this._children[key]
  103. };
  104. Module.prototype.update = function update (rawModule) {
  105. this._rawModule.namespaced = rawModule.namespaced;
  106. if (rawModule.actions) {
  107. this._rawModule.actions = rawModule.actions;
  108. }
  109. if (rawModule.mutations) {
  110. this._rawModule.mutations = rawModule.mutations;
  111. }
  112. if (rawModule.getters) {
  113. this._rawModule.getters = rawModule.getters;
  114. }
  115. };
  116. Module.prototype.forEachChild = function forEachChild (fn) {
  117. forEachValue(this._children, fn);
  118. };
  119. Module.prototype.forEachGetter = function forEachGetter (fn) {
  120. if (this._rawModule.getters) {
  121. forEachValue(this._rawModule.getters, fn);
  122. }
  123. };
  124. Module.prototype.forEachAction = function forEachAction (fn) {
  125. if (this._rawModule.actions) {
  126. forEachValue(this._rawModule.actions, fn);
  127. }
  128. };
  129. Module.prototype.forEachMutation = function forEachMutation (fn) {
  130. if (this._rawModule.mutations) {
  131. forEachValue(this._rawModule.mutations, fn);
  132. }
  133. };
  134. Object.defineProperties( Module.prototype, prototypeAccessors$1 );
  135. var ModuleCollection = function ModuleCollection (rawRootModule) {
  136. // register root module (Vuex.Store options)
  137. this.register([], rawRootModule, false);
  138. };
  139. ModuleCollection.prototype.get = function get (path) {
  140. return path.reduce(function (module, key) {
  141. return module.getChild(key)
  142. }, this.root)
  143. };
  144. ModuleCollection.prototype.getNamespace = function getNamespace (path) {
  145. var module = this.root;
  146. return path.reduce(function (namespace, key) {
  147. module = module.getChild(key);
  148. return namespace + (module.namespaced ? key + '/' : '')
  149. }, '')
  150. };
  151. ModuleCollection.prototype.update = function update$1 (rawRootModule) {
  152. update([], this.root, rawRootModule);
  153. };
  154. ModuleCollection.prototype.register = function register (path, rawModule, runtime) {
  155. var this$1 = this;
  156. if ( runtime === void 0 ) runtime = true;
  157. if (process.env.NODE_ENV !== 'production') {
  158. assertRawModule(path, rawModule);
  159. }
  160. var newModule = new Module(rawModule, runtime);
  161. if (path.length === 0) {
  162. this.root = newModule;
  163. } else {
  164. var parent = this.get(path.slice(0, -1));
  165. parent.addChild(path[path.length - 1], newModule);
  166. }
  167. // register nested modules
  168. if (rawModule.modules) {
  169. forEachValue(rawModule.modules, function (rawChildModule, key) {
  170. this$1.register(path.concat(key), rawChildModule, runtime);
  171. });
  172. }
  173. };
  174. ModuleCollection.prototype.unregister = function unregister (path) {
  175. var parent = this.get(path.slice(0, -1));
  176. var key = path[path.length - 1];
  177. if (!parent.getChild(key).runtime) { return }
  178. parent.removeChild(key);
  179. };
  180. function update (path, targetModule, newModule) {
  181. if (process.env.NODE_ENV !== 'production') {
  182. assertRawModule(path, newModule);
  183. }
  184. // update target module
  185. targetModule.update(newModule);
  186. // update nested modules
  187. if (newModule.modules) {
  188. for (var key in newModule.modules) {
  189. if (!targetModule.getChild(key)) {
  190. if (process.env.NODE_ENV !== 'production') {
  191. console.warn(
  192. "[vuex] trying to add a new module '" + key + "' on hot reloading, " +
  193. 'manual reload is needed'
  194. );
  195. }
  196. return
  197. }
  198. update(
  199. path.concat(key),
  200. targetModule.getChild(key),
  201. newModule.modules[key]
  202. );
  203. }
  204. }
  205. }
  206. var functionAssert = {
  207. assert: function (value) { return typeof value === 'function'; },
  208. expected: 'function'
  209. };
  210. var objectAssert = {
  211. assert: function (value) { return typeof value === 'function' ||
  212. (typeof value === 'object' && typeof value.handler === 'function'); },
  213. expected: 'function or object with "handler" function'
  214. };
  215. var assertTypes = {
  216. getters: functionAssert,
  217. mutations: functionAssert,
  218. actions: objectAssert
  219. };
  220. function assertRawModule (path, rawModule) {
  221. Object.keys(assertTypes).forEach(function (key) {
  222. if (!rawModule[key]) { return }
  223. var assertOptions = assertTypes[key];
  224. forEachValue(rawModule[key], function (value, type) {
  225. assert(
  226. assertOptions.assert(value),
  227. makeAssertionMessage(path, key, type, value, assertOptions.expected)
  228. );
  229. });
  230. });
  231. }
  232. function makeAssertionMessage (path, key, type, value, expected) {
  233. var buf = key + " should be " + expected + " but \"" + key + "." + type + "\"";
  234. if (path.length > 0) {
  235. buf += " in module \"" + (path.join('.')) + "\"";
  236. }
  237. buf += " is " + (JSON.stringify(value)) + ".";
  238. return buf
  239. }
  240. var Vue; // bind on install
  241. var Store = function Store (options) {
  242. var this$1 = this;
  243. if ( options === void 0 ) options = {};
  244. // Auto install if it is not done yet and `window` has `Vue`.
  245. // To allow users to avoid auto-installation in some cases,
  246. // this code should be placed here. See #731
  247. if (!Vue && typeof window !== 'undefined' && window.Vue) {
  248. install(window.Vue);
  249. }
  250. if (process.env.NODE_ENV !== 'production') {
  251. assert(Vue, "must call Vue.use(Vuex) before creating a store instance.");
  252. assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.");
  253. assert(this instanceof Store, "Store must be called with the new operator.");
  254. }
  255. var plugins = options.plugins; if ( plugins === void 0 ) plugins = [];
  256. var strict = options.strict; if ( strict === void 0 ) strict = false;
  257. var state = options.state; if ( state === void 0 ) state = {};
  258. if (typeof state === 'function') {
  259. state = state() || {};
  260. }
  261. // store internal state
  262. this._committing = false;
  263. this._actions = Object.create(null);
  264. this._actionSubscribers = [];
  265. this._mutations = Object.create(null);
  266. this._wrappedGetters = Object.create(null);
  267. this._modules = new ModuleCollection(options);
  268. this._modulesNamespaceMap = Object.create(null);
  269. this._subscribers = [];
  270. this._watcherVM = new Vue();
  271. // bind commit and dispatch to self
  272. var store = this;
  273. var ref = this;
  274. var dispatch = ref.dispatch;
  275. var commit = ref.commit;
  276. this.dispatch = function boundDispatch (type, payload) {
  277. return dispatch.call(store, type, payload)
  278. };
  279. this.commit = function boundCommit (type, payload, options) {
  280. return commit.call(store, type, payload, options)
  281. };
  282. // strict mode
  283. this.strict = strict;
  284. // init root module.
  285. // this also recursively registers all sub-modules
  286. // and collects all module getters inside this._wrappedGetters
  287. installModule(this, state, [], this._modules.root);
  288. // initialize the store vm, which is responsible for the reactivity
  289. // (also registers _wrappedGetters as computed properties)
  290. resetStoreVM(this, state);
  291. // apply plugins
  292. plugins.forEach(function (plugin) { return plugin(this$1); });
  293. if (Vue.config.devtools) {
  294. devtoolPlugin(this);
  295. }
  296. };
  297. var prototypeAccessors = { state: { configurable: true } };
  298. prototypeAccessors.state.get = function () {
  299. return this._vm._data.$$state
  300. };
  301. prototypeAccessors.state.set = function (v) {
  302. if (process.env.NODE_ENV !== 'production') {
  303. assert(false, "Use store.replaceState() to explicit replace store state.");
  304. }
  305. };
  306. Store.prototype.commit = function commit (_type, _payload, _options) {
  307. var this$1 = this;
  308. // check object-style commit
  309. var ref = unifyObjectStyle(_type, _payload, _options);
  310. var type = ref.type;
  311. var payload = ref.payload;
  312. var options = ref.options;
  313. var mutation = { type: type, payload: payload };
  314. var entry = this._mutations[type];
  315. if (!entry) {
  316. if (process.env.NODE_ENV !== 'production') {
  317. console.error(("[vuex] unknown mutation type: " + type));
  318. }
  319. return
  320. }
  321. this._withCommit(function () {
  322. entry.forEach(function commitIterator (handler) {
  323. handler(payload);
  324. });
  325. });
  326. this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); });
  327. if (
  328. process.env.NODE_ENV !== 'production' &&
  329. options && options.silent
  330. ) {
  331. console.warn(
  332. "[vuex] mutation type: " + type + ". Silent option has been removed. " +
  333. 'Use the filter functionality in the vue-devtools'
  334. );
  335. }
  336. };
  337. Store.prototype.dispatch = function dispatch (_type, _payload) {
  338. var this$1 = this;
  339. // check object-style dispatch
  340. var ref = unifyObjectStyle(_type, _payload);
  341. var type = ref.type;
  342. var payload = ref.payload;
  343. var action = { type: type, payload: payload };
  344. var entry = this._actions[type];
  345. if (!entry) {
  346. if (process.env.NODE_ENV !== 'production') {
  347. console.error(("[vuex] unknown action type: " + type));
  348. }
  349. return
  350. }
  351. this._actionSubscribers.forEach(function (sub) { return sub(action, this$1.state); });
  352. return entry.length > 1
  353. ? Promise.all(entry.map(function (handler) { return handler(payload); }))
  354. : entry[0](payload)
  355. };
  356. Store.prototype.subscribe = function subscribe (fn) {
  357. return genericSubscribe(fn, this._subscribers)
  358. };
  359. Store.prototype.subscribeAction = function subscribeAction (fn) {
  360. return genericSubscribe(fn, this._actionSubscribers)
  361. };
  362. Store.prototype.watch = function watch (getter, cb, options) {
  363. var this$1 = this;
  364. if (process.env.NODE_ENV !== 'production') {
  365. assert(typeof getter === 'function', "store.watch only accepts a function.");
  366. }
  367. return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options)
  368. };
  369. Store.prototype.replaceState = function replaceState (state) {
  370. var this$1 = this;
  371. this._withCommit(function () {
  372. this$1._vm._data.$$state = state;
  373. });
  374. };
  375. Store.prototype.registerModule = function registerModule (path, rawModule, options) {
  376. if ( options === void 0 ) options = {};
  377. if (typeof path === 'string') { path = [path]; }
  378. if (process.env.NODE_ENV !== 'production') {
  379. assert(Array.isArray(path), "module path must be a string or an Array.");
  380. assert(path.length > 0, 'cannot register the root module by using registerModule.');
  381. }
  382. this._modules.register(path, rawModule);
  383. installModule(this, this.state, path, this._modules.get(path), options.preserveState);
  384. // reset store to update getters...
  385. resetStoreVM(this, this.state);
  386. };
  387. Store.prototype.unregisterModule = function unregisterModule (path) {
  388. var this$1 = this;
  389. if (typeof path === 'string') { path = [path]; }
  390. if (process.env.NODE_ENV !== 'production') {
  391. assert(Array.isArray(path), "module path must be a string or an Array.");
  392. }
  393. this._modules.unregister(path);
  394. this._withCommit(function () {
  395. var parentState = getNestedState(this$1.state, path.slice(0, -1));
  396. Vue.delete(parentState, path[path.length - 1]);
  397. });
  398. resetStore(this);
  399. };
  400. Store.prototype.hotUpdate = function hotUpdate (newOptions) {
  401. this._modules.update(newOptions);
  402. resetStore(this, true);
  403. };
  404. Store.prototype._withCommit = function _withCommit (fn) {
  405. var committing = this._committing;
  406. this._committing = true;
  407. fn();
  408. this._committing = committing;
  409. };
  410. Object.defineProperties( Store.prototype, prototypeAccessors );
  411. function genericSubscribe (fn, subs) {
  412. if (subs.indexOf(fn) < 0) {
  413. subs.push(fn);
  414. }
  415. return function () {
  416. var i = subs.indexOf(fn);
  417. if (i > -1) {
  418. subs.splice(i, 1);
  419. }
  420. }
  421. }
  422. function resetStore (store, hot) {
  423. store._actions = Object.create(null);
  424. store._mutations = Object.create(null);
  425. store._wrappedGetters = Object.create(null);
  426. store._modulesNamespaceMap = Object.create(null);
  427. var state = store.state;
  428. // init all modules
  429. installModule(store, state, [], store._modules.root, true);
  430. // reset vm
  431. resetStoreVM(store, state, hot);
  432. }
  433. function resetStoreVM (store, state, hot) {
  434. var oldVm = store._vm;
  435. // bind store public getters
  436. store.getters = {};
  437. var wrappedGetters = store._wrappedGetters;
  438. var computed = {};
  439. forEachValue(wrappedGetters, function (fn, key) {
  440. // use computed to leverage its lazy-caching mechanism
  441. computed[key] = function () { return fn(store); };
  442. Object.defineProperty(store.getters, key, {
  443. get: function () { return store._vm[key]; },
  444. enumerable: true // for local getters
  445. });
  446. });
  447. // use a Vue instance to store the state tree
  448. // suppress warnings just in case the user has added
  449. // some funky global mixins
  450. var silent = Vue.config.silent;
  451. Vue.config.silent = true;
  452. store._vm = new Vue({
  453. data: {
  454. $$state: state
  455. },
  456. computed: computed
  457. });
  458. Vue.config.silent = silent;
  459. // enable strict mode for new vm
  460. if (store.strict) {
  461. enableStrictMode(store);
  462. }
  463. if (oldVm) {
  464. if (hot) {
  465. // dispatch changes in all subscribed watchers
  466. // to force getter re-evaluation for hot reloading.
  467. store._withCommit(function () {
  468. oldVm._data.$$state = null;
  469. });
  470. }
  471. Vue.nextTick(function () { return oldVm.$destroy(); });
  472. }
  473. }
  474. function installModule (store, rootState, path, module, hot) {
  475. var isRoot = !path.length;
  476. var namespace = store._modules.getNamespace(path);
  477. // register in namespace map
  478. if (module.namespaced) {
  479. store._modulesNamespaceMap[namespace] = module;
  480. }
  481. // set state
  482. if (!isRoot && !hot) {
  483. var parentState = getNestedState(rootState, path.slice(0, -1));
  484. var moduleName = path[path.length - 1];
  485. store._withCommit(function () {
  486. Vue.set(parentState, moduleName, module.state);
  487. });
  488. }
  489. var local = module.context = makeLocalContext(store, namespace, path);
  490. module.forEachMutation(function (mutation, key) {
  491. var namespacedType = namespace + key;
  492. registerMutation(store, namespacedType, mutation, local);
  493. });
  494. module.forEachAction(function (action, key) {
  495. var type = action.root ? key : namespace + key;
  496. var handler = action.handler || action;
  497. registerAction(store, type, handler, local);
  498. });
  499. module.forEachGetter(function (getter, key) {
  500. var namespacedType = namespace + key;
  501. registerGetter(store, namespacedType, getter, local);
  502. });
  503. module.forEachChild(function (child, key) {
  504. installModule(store, rootState, path.concat(key), child, hot);
  505. });
  506. }
  507. /**
  508. * make localized dispatch, commit, getters and state
  509. * if there is no namespace, just use root ones
  510. */
  511. function makeLocalContext (store, namespace, path) {
  512. var noNamespace = namespace === '';
  513. var local = {
  514. dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) {
  515. var args = unifyObjectStyle(_type, _payload, _options);
  516. var payload = args.payload;
  517. var options = args.options;
  518. var type = args.type;
  519. if (!options || !options.root) {
  520. type = namespace + type;
  521. if (process.env.NODE_ENV !== 'production' && !store._actions[type]) {
  522. console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type));
  523. return
  524. }
  525. }
  526. return store.dispatch(type, payload)
  527. },
  528. commit: noNamespace ? store.commit : function (_type, _payload, _options) {
  529. var args = unifyObjectStyle(_type, _payload, _options);
  530. var payload = args.payload;
  531. var options = args.options;
  532. var type = args.type;
  533. if (!options || !options.root) {
  534. type = namespace + type;
  535. if (process.env.NODE_ENV !== 'production' && !store._mutations[type]) {
  536. console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type));
  537. return
  538. }
  539. }
  540. store.commit(type, payload, options);
  541. }
  542. };
  543. // getters and state object must be gotten lazily
  544. // because they will be changed by vm update
  545. Object.defineProperties(local, {
  546. getters: {
  547. get: noNamespace
  548. ? function () { return store.getters; }
  549. : function () { return makeLocalGetters(store, namespace); }
  550. },
  551. state: {
  552. get: function () { return getNestedState(store.state, path); }
  553. }
  554. });
  555. return local
  556. }
  557. function makeLocalGetters (store, namespace) {
  558. var gettersProxy = {};
  559. var splitPos = namespace.length;
  560. Object.keys(store.getters).forEach(function (type) {
  561. // skip if the target getter is not match this namespace
  562. if (type.slice(0, splitPos) !== namespace) { return }
  563. // extract local getter type
  564. var localType = type.slice(splitPos);
  565. // Add a port to the getters proxy.
  566. // Define as getter property because
  567. // we do not want to evaluate the getters in this time.
  568. Object.defineProperty(gettersProxy, localType, {
  569. get: function () { return store.getters[type]; },
  570. enumerable: true
  571. });
  572. });
  573. return gettersProxy
  574. }
  575. function registerMutation (store, type, handler, local) {
  576. var entry = store._mutations[type] || (store._mutations[type] = []);
  577. entry.push(function wrappedMutationHandler (payload) {
  578. handler.call(store, local.state, payload);
  579. });
  580. }
  581. function registerAction (store, type, handler, local) {
  582. var entry = store._actions[type] || (store._actions[type] = []);
  583. entry.push(function wrappedActionHandler (payload, cb) {
  584. var res = handler.call(store, {
  585. dispatch: local.dispatch,
  586. commit: local.commit,
  587. getters: local.getters,
  588. state: local.state,
  589. rootGetters: store.getters,
  590. rootState: store.state
  591. }, payload, cb);
  592. if (!isPromise(res)) {
  593. res = Promise.resolve(res);
  594. }
  595. if (store._devtoolHook) {
  596. return res.catch(function (err) {
  597. store._devtoolHook.emit('vuex:error', err);
  598. throw err
  599. })
  600. } else {
  601. return res
  602. }
  603. });
  604. }
  605. function registerGetter (store, type, rawGetter, local) {
  606. if (store._wrappedGetters[type]) {
  607. if (process.env.NODE_ENV !== 'production') {
  608. console.error(("[vuex] duplicate getter key: " + type));
  609. }
  610. return
  611. }
  612. store._wrappedGetters[type] = function wrappedGetter (store) {
  613. return rawGetter(
  614. local.state, // local state
  615. local.getters, // local getters
  616. store.state, // root state
  617. store.getters // root getters
  618. )
  619. };
  620. }
  621. function enableStrictMode (store) {
  622. store._vm.$watch(function () { return this._data.$$state }, function () {
  623. if (process.env.NODE_ENV !== 'production') {
  624. assert(store._committing, "Do not mutate vuex store state outside mutation handlers.");
  625. }
  626. }, { deep: true, sync: true });
  627. }
  628. function getNestedState (state, path) {
  629. return path.length
  630. ? path.reduce(function (state, key) { return state[key]; }, state)
  631. : state
  632. }
  633. function unifyObjectStyle (type, payload, options) {
  634. if (isObject(type) && type.type) {
  635. options = payload;
  636. payload = type;
  637. type = type.type;
  638. }
  639. if (process.env.NODE_ENV !== 'production') {
  640. assert(typeof type === 'string', ("Expects string as the type, but found " + (typeof type) + "."));
  641. }
  642. return { type: type, payload: payload, options: options }
  643. }
  644. function install (_Vue) {
  645. if (Vue && _Vue === Vue) {
  646. if (process.env.NODE_ENV !== 'production') {
  647. console.error(
  648. '[vuex] already installed. Vue.use(Vuex) should be called only once.'
  649. );
  650. }
  651. return
  652. }
  653. Vue = _Vue;
  654. applyMixin(Vue);
  655. }
  656. var mapState = normalizeNamespace(function (namespace, states) {
  657. var res = {};
  658. normalizeMap(states).forEach(function (ref) {
  659. var key = ref.key;
  660. var val = ref.val;
  661. res[key] = function mappedState () {
  662. var state = this.$store.state;
  663. var getters = this.$store.getters;
  664. if (namespace) {
  665. var module = getModuleByNamespace(this.$store, 'mapState', namespace);
  666. if (!module) {
  667. return
  668. }
  669. state = module.context.state;
  670. getters = module.context.getters;
  671. }
  672. return typeof val === 'function'
  673. ? val.call(this, state, getters)
  674. : state[val]
  675. };
  676. // mark vuex getter for devtools
  677. res[key].vuex = true;
  678. });
  679. return res
  680. });
  681. var mapMutations = normalizeNamespace(function (namespace, mutations) {
  682. var res = {};
  683. normalizeMap(mutations).forEach(function (ref) {
  684. var key = ref.key;
  685. var val = ref.val;
  686. res[key] = function mappedMutation () {
  687. var args = [], len = arguments.length;
  688. while ( len-- ) args[ len ] = arguments[ len ];
  689. var commit = this.$store.commit;
  690. if (namespace) {
  691. var module = getModuleByNamespace(this.$store, 'mapMutations', namespace);
  692. if (!module) {
  693. return
  694. }
  695. commit = module.context.commit;
  696. }
  697. return typeof val === 'function'
  698. ? val.apply(this, [commit].concat(args))
  699. : commit.apply(this.$store, [val].concat(args))
  700. };
  701. });
  702. return res
  703. });
  704. var mapGetters = normalizeNamespace(function (namespace, getters) {
  705. var res = {};
  706. normalizeMap(getters).forEach(function (ref) {
  707. var key = ref.key;
  708. var val = ref.val;
  709. val = namespace + val;
  710. res[key] = function mappedGetter () {
  711. if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) {
  712. return
  713. }
  714. if (process.env.NODE_ENV !== 'production' && !(val in this.$store.getters)) {
  715. console.error(("[vuex] unknown getter: " + val));
  716. return
  717. }
  718. return this.$store.getters[val]
  719. };
  720. // mark vuex getter for devtools
  721. res[key].vuex = true;
  722. });
  723. return res
  724. });
  725. var mapActions = normalizeNamespace(function (namespace, actions) {
  726. var res = {};
  727. normalizeMap(actions).forEach(function (ref) {
  728. var key = ref.key;
  729. var val = ref.val;
  730. res[key] = function mappedAction () {
  731. var args = [], len = arguments.length;
  732. while ( len-- ) args[ len ] = arguments[ len ];
  733. var dispatch = this.$store.dispatch;
  734. if (namespace) {
  735. var module = getModuleByNamespace(this.$store, 'mapActions', namespace);
  736. if (!module) {
  737. return
  738. }
  739. dispatch = module.context.dispatch;
  740. }
  741. return typeof val === 'function'
  742. ? val.apply(this, [dispatch].concat(args))
  743. : dispatch.apply(this.$store, [val].concat(args))
  744. };
  745. });
  746. return res
  747. });
  748. var createNamespacedHelpers = function (namespace) { return ({
  749. mapState: mapState.bind(null, namespace),
  750. mapGetters: mapGetters.bind(null, namespace),
  751. mapMutations: mapMutations.bind(null, namespace),
  752. mapActions: mapActions.bind(null, namespace)
  753. }); };
  754. function normalizeMap (map) {
  755. return Array.isArray(map)
  756. ? map.map(function (key) { return ({ key: key, val: key }); })
  757. : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); })
  758. }
  759. function normalizeNamespace (fn) {
  760. return function (namespace, map) {
  761. if (typeof namespace !== 'string') {
  762. map = namespace;
  763. namespace = '';
  764. } else if (namespace.charAt(namespace.length - 1) !== '/') {
  765. namespace += '/';
  766. }
  767. return fn(namespace, map)
  768. }
  769. }
  770. function getModuleByNamespace (store, helper, namespace) {
  771. var module = store._modulesNamespaceMap[namespace];
  772. if (process.env.NODE_ENV !== 'production' && !module) {
  773. console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace));
  774. }
  775. return module
  776. }
  777. var index = {
  778. Store: Store,
  779. install: install,
  780. version: '3.0.1',
  781. mapState: mapState,
  782. mapMutations: mapMutations,
  783. mapGetters: mapGetters,
  784. mapActions: mapActions,
  785. createNamespacedHelpers: createNamespacedHelpers
  786. };
  787. module.exports = index;