From 7f50e3d137de237907cef0418130dde4d7fc62b5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 12 Aug 2020 17:39:11 +0200 Subject: [PATCH] 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 --- src/domain/ViewModel.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/domain/ViewModel.js b/src/domain/ViewModel.js index 2f34e536..4f73702a 100644 --- a/src/domain/ViewModel.js +++ b/src/domain/ViewModel.js @@ -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() {