8000 [build] 1.0.0-rc.2 · poorprogrammer/vuejs.org@1ca2d55 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1ca2d55

Browse files
committed
[build] 1.0.0-rc.2
1 parent 112b6b7 commit 1ca2d55

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

dist/vuex.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Vuex v1.0.0-rc
2+
* Vuex v1.0.0-rc.2
33
* (c) 2016 Evan You
44
* Released under the MIT License.
55
*/
@@ -135,7 +135,7 @@
135135
store.replaceState(targetState);
136136
});
137137

138-
store.on('mutation', function (mutation, state) {
138+
store.subscribe(function (mutation, state) {
139139
hook.emit('vuex:mutation', mutation, state);
140140
});
141141
}
@@ -341,7 +341,7 @@
341341
this._dispatching = false;
342342
this._rootMutations = this._mutations = mutations;
343343
this._modules = modules;
344-
this._events = Object.create(null);
344+
this._subscribers = [];
345345
// bind dispatch to self
346346
var dispatch = this.dispatch;
347347
this.dispatch = function () {
@@ -410,6 +410,8 @@
410410
}, {
411411
key: 'dispatch',
412412
value: function dispatch(type) {
413+
var _this2 = this;
414+
413415
for (var _len2 = arguments.length, payload = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
414416
payload[_key2 - 1] = arguments[_key2];
415417
}
@@ -437,8 +439,12 @@
437439
}
438440
this._dispatching = false;
439441
if (!silent) {
440-
var mutation = isObjectStyleDispatch ? payload : { type: type, payload: payload };
441-
this.emit('mutation', mutation, state);
442+
(function () {
443+
var mutation = isObjectStyleDispatch ? payload : { type: type, payload: payload };
444+
_this2._subscribers.forEach(function (sub) {
445+
return sub(mutation, state);
446+
});
447+
})();
442448
}
443449
} else {
444450
console.warn('[vuex] Unknown mutation: ' + type);
@@ -458,17 +464,36 @@
458464
}, {
459465
key: 'watch',
460466
value: function watch(fn, cb, options) {
461-
var _this2 = this;
467+
var _this3 = this;
462468

463469
if (typeof fn !== 'function') {
464470
console.error('Vuex store.watch only accepts function.');
465471
return;
466472
}
467473
return this._vm.$watch(function () {
468-
return fn(_this2.state);
474+
return fn(_this3.state);
469475
}, cb, options);
470476
}
471477

478+
/**
479+
* Subscribe to state changes. Fires after every mutation.
480+
*/
481+
482+
}, {
483+
key: 'subscribe',
484+
value: function subscribe(fn) {
485+
var subs = this._subscribers;
486+
if (subs.indexOf(fn) < 0) {
487+
subs.push(fn);
488+
}
489+
return function () {
490+
var i = subs.indexOf(fn);
491+
if (i > -1) {
492+
subs.splice(i, 1);
493+
}
494+
};
495+
}
496+
472497
/**
473498
* Hot update mutations & modules.
474499
*
@@ -499,7 +524,7 @@
499524
}, {
500525
key: '_setupModuleState',
501526
value: function _setupModuleState(state, modules) {
502-
var _this3 = this;
527+
var _this4 = this;
503528

504529
if (!isObject(modules)) return;
505530

@@ -510,7 +535,7 @@
510535
Vue.set(state, key, module.state || {});
511536

512537
// retrieve nested modules
513-
_this3._setupModuleState(state[key], module.modules);
538+
_this4._setupModuleState(state[key], module.modules);
514539
});
515540
}
516541

@@ -545,7 +570,7 @@
545570
}, {
546571
key: '_createModuleMutations',
547572
value: function _createModuleMutations(modules, nestedKeys) {
548-
var _this4 = this;
573+
var _this5 = this;
549574

550575
if (!isObject(modules)) return [];
551576

@@ -554,7 +579,7 @@
554579
var newNestedKeys = nestedKeys.concat(key);
555580

556581
// retrieve nested modules
557-
var nestedMutations = _this4._createModuleMutations(module.modules, newNestedKeys);
582+
var nestedMutations = _this5._createModuleMutations(module.modules, newNestedKeys);
558583

559584
if (!module || !module.mutations) {
560585
return mergeObjects(nestedMutations);
@@ -590,12 +615,12 @@
590615
}, {
591616
key: '_setupMutationCheck',
592617
value: function _setupMutationCheck() {
593-
var _this5 = this;
618+
var _this6 = this;
594619

595620
var Watcher = getWatcher(this._vm);
596621
/* eslint-disable no-new */
597622
new Watcher(this._vm, 'state', function () {
598-
if (!_this5._dispatching) {
623+
if (!_this6._dispatching) {
599624
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');
600625
}
601626
}, { deep: true, sync: true });
@@ -618,11 +643,7 @@
618643
console.warn('[vuex] already installed. Vue.use(Vuex) should be called only once.');
619644
return;
620645
}
621-
Vue = _Vue
622-
// reuse Vue's event system
623-
;['on', 'off', 'once', 'emit'].forEach(function (e) {
624-
Store.prototype[e] = Store.prototype['$' + e] = Vue.prototype['$' + e];
625-
});
646+
Vue = _Vue;
626647
override(Vue);
627648
}
628649

dist/vuex.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0