|
1 | 1 | /**
|
2 |
| - * vuex v2.2.0 |
| 2 | + * vuex v2.2.1 |
3 | 3 | * (c) 2017 Evan You
|
4 | 4 | * @license MIT
|
5 | 5 | */
|
@@ -236,122 +236,6 @@ function update (targetModule, newModule) {
|
236 | 236 | }
|
237 | 237 | }
|
238 | 238 |
|
239 |
| -var mapState = normalizeNamespace(function (namespace, states) { |
240 |
| - var res = {}; |
241 |
| - normalizeMap(states).forEach(function (ref) { |
242 |
| - var key = ref.key; |
243 |
| - var val = ref.val; |
244 |
| - |
245 |
| - res[key] = function mappedState () { |
246 |
| - var state = this.$store.state; |
247 |
| - var getters = this.$store.getters; |
248 |
| - if (namespace) { |
249 |
| - var module = getModuleByNamespace(this.$store, 'mapState', namespace); |
250 |
| - if (!module) { |
251 |
| - return |
252 |
| - } |
253 |
| - state = module.context.state; |
254 |
| - getters = module.context.getters; |
255 |
| - } |
256 |
| - return typeof val === 'function' |
257 |
| - ? val.call(this, state, getters) |
258 |
| - : state[val] |
259 |
| - }; |
260 |
| - // mark vuex getter for devtools |
261 |
| - res[key].vuex = true; |
262 |
| - }); |
263 |
| - return res |
264 |
| -}); |
265 |
| - |
266 |
| -var mapMutations = normalizeNamespace(function (namespace, mutations) { |
267 |
| - var res = {}; |
268 |
| - normalizeMap(mutations).forEach(function (ref) { |
269 |
| - var key = ref.key; |
270 |
| - var val = ref.val; |
271 |
| - |
272 |
| - val = namespace + val; |
273 |
| - res[key] = function mappedMutation () { |
274 |
| - var args = [], len = arguments.length; |
275 |
| - while ( len-- ) args[ len ] = arguments[ len ]; |
276 |
| - |
277 |
| - if (namespace && !getModuleByNamespace(this.$store, 'mapMutations', namespace)) { |
278 |
| - return |
279 |
| - } |
280 |
| - return this.$store.commit.apply(this.$store, [val].concat(args)) |
281 |
| - }; |
282 |
| - }); |
283 |
| - return res |
284 |
| -}); |
285 |
| - |
286 |
| -var mapGetters = normalizeNamespace(function (namespace, getters) { |
287 |
| - var res = {}; |
288 |
| - normalizeMap(getters).forEach(function (ref) { |
289 |
| - var key = ref.key; |
290 |
| - var val = ref.val; |
291 |
| - |
292 |
| - val = namespace + val; |
293 |
| - res[key] = function mappedGetter () { |
294 |
| - if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { |
295 |
| - return |
296 |
| - } |
297 |
| - if (!(val in this.$store.getters)) { |
298 |
| - console.error(("[vuex] unknown getter: " + val)); |
299 |
| - return |
300 |
| - } |
301 |
| - return this.$store.getters[val] |
302 |
| - }; |
303 |
| - // mark vuex getter for devtools |
304 |
| - res[key].vuex = true; |
305 |
| - }); |
306 |
| - return res |
307 |
| -}); |
308 |
| - |
309 |
| -var mapActions = normalizeNamespace(function (namespace, actions) { |
310 |
| - var res = {}; |
311 |
| - normalizeMap(actions).forEach(function (ref) { |
312 |
| - var key = ref.key; |
313 |
| - var val = ref.val; |
314 |
| - |
315 |
| - val = namespace + val; |
316 |
| - res[key] = function mappedAction () { |
317 |
| - var args = [], len = arguments.length; |
318 |
| - while ( len-- ) args[ len ] = arguments[ len ]; |
319 |
| - |
320 |
| - if (namespace && !getModuleByNamespace(this.$store, 'mapActions', namespace)) { |
321 |
| - return |
322 |
| - } |
323 |
| - return this.$store.dispatch.apply(this.$store, [val].concat(args)) |
324 |
| - }; |
325 |
| - }); |
326 |
| - return res |
327 |
| -}); |
328 |
| - |
329 |
| -function normalizeMap (map) { |
330 |
| - return Array.isArray(map) |
331 |
| - ? map.map(function (key) { return ({ key: key, val: key }); }) |
332 |
| - : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); }) |
333 |
| -} |
334 |
| - |
335 |
| -function normalizeNamespace (fn) { |
336 |
| - return function (namespace, map) { |
337 |
| - if (typeof namespace !== 'string') { |
338 |
| - map = namespace; |
339 |
| - namespace = ''; |
340 |
| - } else if (namespace.charAt(namespace.length - 1) !== '/') { |
341 |
| - namespace += '/'; |
342 |
| - } |
343 |
| - return fn(namespace, map) |
344 |
| - } |
345 |
| -} |
346 |
| - |
347 |
| -function getModuleByNamespace (store, helper, namespace) { |
348 |
| - var module = store._modulesNamespaceMap[namespace]; |
349 |
| - if (!module) { |
350 |
| - console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); |
351 |
| - } |
352 |
| - return module |
353 |
| -} |
354 |
| - |
355 | 239 | var Vue; // bind on install
|
356 | 240 |
|
357 | 241 | var Store = function Store (options) {
|
@@ -790,14 +674,130 @@ if (typeof window !== 'undefined' && window.Vue) {
|
790 | 674 | install(window.Vue);
|
791 | 675 | }
|
792 | 676 |
|
793 |
| -var index = { |
| 677 | +var mapState = normalizeNamespace(function (namespace, states) { |
| 678 | + var res = {}; |
| 679 | + normalizeMap(states).forEach(function (ref) { |
| 680 | + var key = ref.key; |
| 681 | + var val = ref.val; |
| 682 | + |
| 683 | + res[key] = function mappedState () { |
| 684 | + var state = this.$store.state; |
| 685 | + var getters = this.$store.getters; |
| 686 | + if (namespace) { |
| 687 | + var module = getModuleByNamespace(this.$store, 'mapState', namespace); |
| 688 | + if (!module) { |
| 689 | + return |
| 690 | + } |
| 691 | + state = module.context.state; |
| 692 | + getters = module.context.getters; |
| 693 | + } |
| 694 | + return typeof val === 'function' |
| 695 | + ? val.call(this, state, getters) |
| 696 | + : state[val] |
| 697 | + }; |
| 698 | + // mark vuex getter for devtools |
| 699 | + res[key].vuex = true; |
| 700 | + }); |
| 701 | + return res |
| 702 | +}); |
| 703 | + |
| 704 | +var mapMutations = normalizeNamespace(function (namespace, mutations) { |
| 705 | + var res = {}; |
| 706 | + normalizeMap(mutations).forEach(function (ref) { |
| 707 | + var key = ref.key; |
| 708 | + var val = ref.val; |
| 709 | + |
| 710 | + val = namespace + val; |
| 711 | + res[key] = function mappedMutation () { |
| 712 | + var args = [], len = arguments.length; |
| 713 | + while ( len-- ) args[ len ] = arguments[ len ]; |
| 714 | + |
| 715 | + if (namespace && !getModuleByNamespace(this.$store, 'mapMutations', namespace)) { |
| 716 | + return |
| 717 | + } |
| 718 | + return this.$store.commit.apply(this.$store, [val].concat(args)) |
| 719 | + }; |
| 720 | + }); |
| 721 | + return res |
| 722 | +}); |
| 723 | + |
| 724 | +var mapGetters = normalizeNamespace(function (namespace, getters) { |
| 725 | + var res = {}; |
| 726 | + normalizeMap(getters).forEach(function (ref) { |
| 727 | + var key = ref.key; |
| 728 | + var val = ref.val; |
| 729 | + |
| 730 | + val = namespace + val; |
| 731 | + res[key] = function mappedGetter () { |
| 732 | + if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { |
| 733 | + return |
| 734 | + } |
| 735 | + if (!(val in this.$store.getters)) { |
| 736 | + console.error(("[vuex] unknown getter: " + val)); |
| 737 | + return |
| 738 | + } |
| 739 | + return this.$store.getters[val] |
| 740 | + }; |
| 741 | + // mark vuex getter for devtools |
| 742 | + res[key].vuex = true; |
| 743 | + }); |
| 744 | + return res |
| 745 | +}); |
| 746 | + |
| 747 | +var mapActions = normalizeNamespace(function (namespace, actions) { |
| 748 | + var res = {}; |
| 749 | + normalizeMap(actions).forEach(function (ref) { |
| 750 | + var key = ref.key; |
| 751 | + var val = ref.val; |
| 752 | + |
| 753 | + val = namespace + val; |
| 754 | + res[key] = function mappedAction () { |
| 755 | + var args = [], len = arguments.length; |
| 756 | + while ( len-- ) args[ len ] = arguments[ len ]; |
| 757 | + |
| 758 | + if (namespace && !getModuleByNamespace(this.$store, 'mapActions', namespace)) { |
| 759 | + return |
| 760 | + } |
| 761 | + return this.$store.dispatch.apply(this.$store, [val].concat(args)) |
| 762 | + }; |
| 763 | + }); |
| 764 | + return res |
| 765 | +}); |
| 766 | + |
| 767 | +function normalizeMap (map) { |
| 768 | + return Array.isArray(map) |
| 769 | + ? map.map(function (key) { return ({ key: key, val: key }); }) |
| 770 | + : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); }) |
| 771 | +} |
| 772 | + |
| 773 | +function normalizeNamespace (fn) { |
| 774 | + return function (namespace, map) { |
| 775 | + if (typeof namespace !== 'string') { |
| 776 | + map = namespace; |
| 777 | + namespace = ''; |
| 778 | + } else if (namespace.charAt(namespace.length - 1) !== '/') { |
| 779 | + namespace += '/'; |
| 780 | + } |
| 781 | + return fn(namespace, map) |
| 782 | + } |
| 783 | +} |
| 784 | + |
| 785 | +function getModuleByNamespace (store, helper, namespace) { |
| 786 | + var module = store._modulesNamespaceMap[namespace]; |
| 787 | + if (!module) { |
| 788 | + console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); |
| 789 | + } |
| 790 | + return module |
| 791 | +} |
| 792 | + |
| 793 | +var index_esm = { |
794 | 794 | Store: Store,
|
795 | 795 | install: install,
|
796 |
| - version: '2.2.0', |
| 796 | + version: '2.2.1', |
797 | 797 | mapState: mapState,
|
798 | 798 | mapMutations: mapMutations,
|
799 | 799 | mapGetters: mapGetters,
|
800 | 800 | mapActions: mapActions
|
801 | 801 | };
|
802 | 802 |
|
803 |
| -export default index; |
| 803 | +export { Store, mapState, mapMutations, mapGetters, mapActions };export default index_esm; |
0 commit comments