From fa37e8fedbcbe973172f6f78bb2994c1ea156e7d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 31 May 2021 10:46:16 +0200 Subject: [PATCH] findAndUpdate uses predicate, just add callback to update method --- src/matrix/room/timeline/Timeline.js | 2 +- src/observable/list/SortedArray.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 5ba65c4d..dffe973b 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -122,7 +122,7 @@ export class Timeline { for (const entry of entries) { // this will use the comparator and thus // check for equality using the compare method in BaseEntry - this._remoteEntries.findAndUpdate(entry, (previousEntry, entry) => { + this._remoteEntries.update(entry, null, previousEntry => { entry.transferLocalEchoState(previousEntry); }); } diff --git a/src/observable/list/SortedArray.js b/src/observable/list/SortedArray.js index d2663f37..f040702d 100644 --- a/src/observable/list/SortedArray.js +++ b/src/observable/list/SortedArray.js @@ -57,9 +57,13 @@ export class SortedArray extends BaseObservableList { return false; } - update(item, updateParams = null) { + update(item, updateParams = null, previousCallback = null) { const idx = this.indexOf(item); if (idx !== -1) { + if (previousCallback) { + const oldItem = this._items[idx]; + previousCallback(oldItem); + } this._items[idx] = item; this.emitUpdate(idx, item, updateParams); }