From b2e6e8687ef5e804cf37c2b7ad94892ba4123122 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 14 Sep 2020 17:44:22 +0200 Subject: [PATCH] dispose tiles also add more defence against emitting event when disposed --- src/domain/session/room/timeline/TilesCollection.js | 9 ++++++--- .../session/room/timeline/tiles/SimpleTile.js | 13 ++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/domain/session/room/timeline/TilesCollection.js b/src/domain/session/room/timeline/TilesCollection.js index 6854bd5e..c2d9df5d 100644 --- a/src/domain/session/room/timeline/TilesCollection.js +++ b/src/domain/session/room/timeline/TilesCollection.js @@ -145,7 +145,7 @@ export class TilesCollection extends BaseObservableList { if (tile) { const action = tile.updateEntry(entry, params); if (action.shouldReplace) { - this._replaceTile(tileIdx, this._tileCreator(entry)); + this._replaceTile(tileIdx, tile, this._tileCreator(entry)); } if (action.shouldRemove) { this._removeTile(tileIdx, tile); @@ -167,7 +167,8 @@ export class TilesCollection extends BaseObservableList { // merge with neighbours? ... hard to imagine use case for this ... } - _replaceTile(tileIdx, newTile) { + _replaceTile(tileIdx, existingTile, newTile) { + existingTile.dispose(); const prevTile = this._getTileAtIdx(tileIdx - 1); const nextTile = this._getTileAtIdx(tileIdx + 1); this._tiles[tileIdx] = newTile; @@ -184,7 +185,7 @@ export class TilesCollection extends BaseObservableList { this._tiles.splice(tileIdx, 1); prevTile && prevTile.updateNextSibling(nextTile); nextTile && nextTile.updatePreviousSibling(prevTile); - tile.setUpdateEmit(null); + tile.dispose(); this.emitRemove(tileIdx, tile); } @@ -254,6 +255,8 @@ export function tests() { updateEntry() { return UpdateAction.Nothing; } + + dispose() {} } return { diff --git a/src/domain/session/room/timeline/tiles/SimpleTile.js b/src/domain/session/room/timeline/tiles/SimpleTile.js index 7b018b37..12acd4c5 100644 --- a/src/domain/session/room/timeline/tiles/SimpleTile.js +++ b/src/domain/session/room/timeline/tiles/SimpleTile.js @@ -48,7 +48,13 @@ export class SimpleTile extends ViewModel { } // TilesCollection contract below setUpdateEmit(emitUpdate) { - this.updateOptions({emitChange: paramName => emitUpdate(this, paramName)}); + this.updateOptions({emitChange: paramName => { + if (emitUpdate) { + emitUpdate(this, paramName); + } else { + console.trace("Tile is emitting event after being disposed"); + } + }}); } get upperEntry() { @@ -88,5 +94,10 @@ export class SimpleTile extends ViewModel { updateNextSibling(next) { } + + dispose() { + this.setUpdateEmit(null); + super.dispose(); + } // TilesCollection contract above }