allow overriding the "emit change" mechanism in ViewModel

so view models that should send updates through their collection
can still use the same "emitChange" method on ViewModel
This commit is contained in:
Bruno Windels 2020-08-12 17:39:11 +02:00
parent fbf72b8825
commit 7f50e3d137

View File

@ -22,10 +22,10 @@ import {EventEmitter} from "../utils/EventEmitter.js";
import {Disposables} from "../utils/Disposables.js";
export class ViewModel extends EventEmitter {
constructor({clock} = {}) {
constructor({clock, emitChange} = {}) {
super();
this.disposables = null;
this._options = {clock};
this._options = {clock, emitChange};
}
childOptions(explicitOptions) {
@ -71,7 +71,11 @@ export class ViewModel extends EventEmitter {
}
emitChange(changedProps) {
this.emit("change", changedProps);
if (this._options.emitChange) {
this._options.emitChange(changedProps);
} else {
this.emit("change", changedProps);
}
}
get clock() {