vuejs-rails 2.1.10 → 2.2.1

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