From 9ea961ae532a240fc44294734a900b8d9496aeca Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 14 Sep 2020 17:43:06 +0200 Subject: [PATCH] don't crash when we don't have a subscription anymore --- src/domain/ViewModel.js | 6 ++++++ src/domain/session/room/timeline/TimelineViewModel.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/domain/ViewModel.js b/src/domain/ViewModel.js index 15812f8c..7f973ad7 100644 --- a/src/domain/ViewModel.js +++ b/src/domain/ViewModel.js @@ -25,6 +25,7 @@ export class ViewModel extends EventEmitter { constructor({clock, emitChange} = {}) { super(); this.disposables = null; + this._isDisposed = false; this._options = {clock, emitChange}; } @@ -43,6 +44,11 @@ export class ViewModel extends EventEmitter { if (this.disposables) { this.disposables.dispose(); } + this._isDisposed = true; + } + + get isDisposed() { + return this._isDisposed; } disposeTracked(disposable) { diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index 16d529cb..a4f662f6 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -50,6 +50,10 @@ export class TimelineViewModel extends ViewModel { * @return {bool} startReached if the start of the timeline was reached */ async loadAtTop() { + if (this.isDisposed) { + // stop loading more, we switched room + return true; + } const firstTile = this._tiles.getFirst(); if (firstTile.shape === "gap") { return firstTile.fill();