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