forked from mystiq/hydrogen-web
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:
parent
fbf72b8825
commit
7f50e3d137
1 changed files with 7 additions and 3 deletions
|
@ -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,8 +71,12 @@ export class ViewModel extends EventEmitter {
|
|||
}
|
||||
|
||||
emitChange(changedProps) {
|
||||
if (this._options.emitChange) {
|
||||
this._options.emitChange(changedProps);
|
||||
} else {
|
||||
this.emit("change", changedProps);
|
||||
}
|
||||
}
|
||||
|
||||
get clock() {
|
||||
return this._options.clock;
|
||||
|
|
Loading…
Reference in a new issue