mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
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
@ -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,8 +71,12 @@ export class ViewModel extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
emitChange(changedProps) {
|
emitChange(changedProps) {
|
||||||
|
if (this._options.emitChange) {
|
||||||
|
this._options.emitChange(changedProps);
|
||||||
|
} else {
|
||||||
this.emit("change", changedProps);
|
this.emit("change", changedProps);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get clock() {
|
get clock() {
|
||||||
return this._options.clock;
|
return this._options.clock;
|
||||||
|
Loading…
Reference in New Issue
Block a user