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";
|
import {Disposables} from "../utils/Disposables.js";
|
||||||
|
|
||||||
export class ViewModel extends EventEmitter {
|
export class ViewModel extends EventEmitter {
|
||||||
constructor({clock} = {}) {
|
constructor({clock, emitChange} = {}) {
|
||||||
super();
|
super();
|
||||||
this.disposables = null;
|
this.disposables = null;
|
||||||
this._options = {clock};
|
this._options = {clock, emitChange};
|
||||||
}
|
}
|
||||||
|
|
||||||
childOptions(explicitOptions) {
|
childOptions(explicitOptions) {
|
||||||
|
@ -71,7 +71,11 @@ export class ViewModel extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
emitChange(changedProps) {
|
emitChange(changedProps) {
|
||||||
this.emit("change", changedProps);
|
if (this._options.emitChange) {
|
||||||
|
this._options.emitChange(changedProps);
|
||||||
|
} else {
|
||||||
|
this.emit("change", changedProps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get clock() {
|
get clock() {
|
||||||
|
|
Loading…
Reference in a new issue