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