From f41c835e91644e1c18798dee21a0309a37594c3e Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 22 Jun 2021 17:33:15 +0530 Subject: [PATCH] Support updater in MappedMap Signed-off-by: RMidhunSuresh --- src/observable/index.js | 4 ++-- src/observable/map/MappedMap.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/observable/index.js b/src/observable/index.js index 4c455407..47b68e91 100644 --- a/src/observable/index.js +++ b/src/observable/index.js @@ -34,8 +34,8 @@ Object.assign(BaseObservableMap.prototype, { return new SortedMapList(this, comparator); }, - mapValues(mapper) { - return new MappedMap(this, mapper); + mapValues(mapper, updater) { + return new MappedMap(this, mapper, updater); }, filterValues(filter) { diff --git a/src/observable/map/MappedMap.js b/src/observable/map/MappedMap.js index ec33c4dd..47013df8 100644 --- a/src/observable/map/MappedMap.js +++ b/src/observable/map/MappedMap.js @@ -20,10 +20,11 @@ so a mapped value can emit updates on it's own with this._emitSpontaneousUpdate how should the mapped value be notified of an update though? and can it then decide to not propagate the update? */ export class MappedMap extends BaseObservableMap { - constructor(source, mapper) { + constructor(source, mapper, updater) { super(); this._source = source; this._mapper = mapper; + this._updater = updater; this._mappedValues = new Map(); } @@ -55,6 +56,7 @@ export class MappedMap extends BaseObservableMap { } const mappedValue = this._mappedValues.get(key); if (mappedValue !== undefined) { + this._updater?.(mappedValue, params, value); // TODO: map params somehow if needed? this.emitUpdate(key, mappedValue, params); }