Skip to content

Commit 6c85280

Browse files
committed
[build] 0.6.3
1 parent 695797c commit 6c85280

File tree

2 files changed

+101
-43
lines changed

2 files changed

+101
-43
lines changed

dist/vuex.js

Lines changed: 99 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Vuex v0.6.2
2+
* Vuex v0.6.3
33
* (c) 2016 Evan You
44
* Released under the MIT License.
55
*/
@@ -158,6 +158,10 @@
158158
_init.call(this, options);
159159
};
160160

161+
/**
162+
* Vuex init hook, injected into each instances init hooks list.
163+
*/
164+
161165
function vuexInit() {
162166
var options = this.$options;
163167
var store = options.store;
@@ -194,27 +198,55 @@
194198
if (actions) {
195199
options.methods = options.methods || {};
196200
for (var _key in actions) {
197-
options.methods[_key] = makeBoundAction(actions[_key], this.$store);
201+
options.methods[_key] = makeBoundAction(this.$store, actions[_key], _key);
198202
}
199203
}
200204
}
201205
}
202206

207+
/**
208+
* Setter for all getter properties.
209+
*/
210+
203211
function setter() {
204212
throw new Error('vuex getter properties are read-only.');
205213
}
206214

215+
/**
216+
* Define a Vuex getter on an instance.
217+
*
218+
* @param {Vue} vm
219+
* @param {String} key
220+
* @param {Function} getter
221+
*/
222+
207223
function defineVuexGetter(vm, key, getter) {
208-
Object.defineProperty(vm, key, {
209-
enumerable: true,
210-
configurable: true,
211-
get: makeComputedGetter(vm.$store, getter),
212-
set: setter
213-
});
224+
if (typeof getter !== 'function') {
225+
console.warn('[vuex] Getter bound to key \'vuex.getters.' + key + '\' is not a function.');
226+
} else {
227+
Object.defineProperty(vm, key, {
228+
enumerable: true,
229+
configurable: true,
230+
get: makeComputedGetter(vm.$store, getter),
231+
set: setter
232+
});
233+
}
214234
}
215235

236+
/**
237+
* Make a computed getter, using the same caching mechanism of computed
238+
* properties. In addition, it is cached on the raw getter function using
239+
* the store's unique cache id. This makes the same getter shared
240+
* across all components use the same underlying watcher, and makes
241+
* the getter evaluated only once during every flush.
242+
*
243+
* @param {Store} store
244+
* @param {Function} getter
245+
*/
246+
216247
function makeComputedGetter(store, getter) {
217248
var id = store._getterCacheId;
249+
218250
// cached
219251
if (getter[id]) {
220252
return getter[id];
@@ -238,7 +270,18 @@
238270
return computedGetter;
239271
}
240272

241-
function makeBoundAction(action, store) {
273+
/**
274+
* Make a bound-to-store version of a raw action function.
275+
*
276+
* @param {Store} store
277+
* @param {Function} action
278+
* @param {String} key
279+
*/
280+
281+
function makeBoundAction(store, action, key) {
282+
if (typeof action !== 'function') {
283+
console.warn('[vuex] Action bound to key \'vuex.actions.' + key + '\' is not a function.');
284+
}
242285
return function vuexBoundAction() {
243286
for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) {
244287
args[_key2] = arguments[_key2];
@@ -344,22 +387,19 @@
344387
*/
345388

346389
value: function dispatch(type) {
347-
var _this2 = this;
348-
349390
for (var _len2 = arguments.length, payload = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
350391
payload[_key2 - 1] = arguments[_key2];
351392
}
352393

394+
var silent = false;
353395
// compatibility for object actions, e.g. FSA
354396
if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) {
355-
payload = [type];
397+
payload = [type.payload];
398+
if (type.silent) silent = true;
356399
type = type.type;
357400
}
358401
var mutation = this._mutations[type];
359-
var prevSnapshot = this._prevSnapshot;
360402
var state = this.state;
361-
var snapshot = void 0,
362-
clonedPayload = void 0;
363403
if (mutation) {
364404
this._dispatching = true;
365405
// apply the mutation
@@ -371,20 +411,7 @@
371411
mutation.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload)));
372412
}
373413
this._dispatching = false;
374-
// invoke middlewares
375-
if (this._needSnapshots) {
376-
snapshot = this._prevSnapshot = deepClone(state);
377-
clonedPayload = deepClone(payload);
378-
}
379-
this._middlewares.forEach(function (m) {
380-
if (m.onMutation) {
381-
if (m.snapshot) {
382-
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this2);
383-
} else {
384-
m.onMutation({ type: type, payload: payload }, state, _this2);
385-
}
386-
}
387-
});
414+
if (!silent) this._applyMiddlewares(type, payload);
388415
} else {
389416
console.warn('[vuex] Unknown mutation: ' + type);
390417
}
@@ -403,10 +430,10 @@
403430
}, {
404431
key: 'watch',
405432
value: function watch(expOrFn, cb, options) {
406-
var _this3 = this;
433+
var _this2 = this;
407434

408435
return this._vm.$watch(function () {
409-
return typeof expOrFn === 'function' ? expOrFn(_this3.state) : _this3._vm.$get(expOrFn);
436+
return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn);
410437
}, cb, options);
411438
}
412439

@@ -440,10 +467,8 @@
440467
}, {
441468
key: '_setupModuleState',
442469
value: function _setupModuleState(state, modules) {
443-
var setPath = Vue.parsers.path.setPath;
444-
445470
Object.keys(modules).forEach(function (key) {
446-
setPath(state, key, modules[key].state || {});
471+
Vue.set(state, key, modules[key].state || {});
447472
});
448473
}
449474

@@ -458,8 +483,6 @@
458483
key: '_setupModuleMutations',
459484
value: function _setupModuleMutations(updatedModules) {
460485
var modules = this._modules;
461-
var getPath = Vue.parsers.path.getPath;
462-
463486
var allMutations = [this._rootMutations];
464487
Object.keys(updatedModules).forEach(function (key) {
465488
modules[key] = updatedModules[key];
@@ -476,7 +499,7 @@
476499
args[_key3 - 1] = arguments[_key3];
477500
}
478501

479-
original.apply(undefined, [getPath(state, key)].concat(args));
502+
original.apply(undefined, [state[key]].concat(args));
480503
};
481504
});
482505
allMutations.push(mutations);
@@ -496,12 +519,12 @@
496519
}, {
497520
key: '_setupMutationCheck',
498521
value: function _setupMutationCheck() {
499-
var _this4 = this;
522+
var _this3 = this;
500523

501524
var Watcher = getWatcher(this._vm);
502525
/* eslint-disable no-new */
503526
new Watcher(this._vm, '$data', function () {
504-
if (!_this4._dispatching) {
527+
if (!_this3._dispatching) {
505528
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');
506529
}
507530
}, { deep: true, sync: true });
@@ -522,7 +545,7 @@
522545
}, {
523546
key: '_setupMiddlewares',
524547
value: function _setupMiddlewares(middlewares, state) {
525-
var _this5 = this;
548+
var _this4 = this;
526549

527550
this._middlewares = [devtoolMiddleware].concat(middlewares);
528551
this._needSnapshots = middlewares.some(function (m) {
@@ -535,7 +558,38 @@
535558
// call init hooks
536559
this._middlewares.forEach(function (m) {
537560
if (m.onInit) {
538-
m.onInit(m.snapshot ? initialSnapshot : state, _this5);
561+
m.onInit(m.snapshot ? initialSnapshot : state, _this4);
562+
}
563+
});
564+
}
565+
566+
/**
567+
* Apply the middlewares on a given mutation.
568+
*
569+
* @param {String} type
570+
* @param {Array} payload
571+
*/
572+
573+
}, {
574+
key: '_applyMiddlewares',
575+
value: function _applyMiddlewares(type, payload) {
576+
var _this5 = this;
577+
578+
var state = this.state;
579+
var prevSnapshot = this._prevSnapshot;
580+
var snapshot = void 0,
581+
clonedPayload = void 0;
582+
if (this._needSnapshots) {
583+
snapshot = this._prevSnapshot = deepClone(state);
584+
clonedPayload = deepClone(payload);
585+
}
586+
this._middlewares.forEach(function (m) {
587+
if (m.onMutation) {
588+
if (m.snapshot) {
589+
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this5);
590+
} else {
591+
m.onMutation({ type: type, payload: payload }, state, _this5);
592+
}
539593
}
540594
});
541595
}
@@ -552,6 +606,10 @@
552606
}();
553607

554608
function install(_Vue) {
609+
if (Vue) {
610+
console.warn('[vuex] already installed. Vue.use(Vuex) should be called only once.');
611+
return;
612+
}
555613
Vue = _Vue;
556614
override(Vue);
557615
}

0 commit comments

Comments
 (0)