From 960e3ec469fa8d472e0f2c3a27cdce6917dbd0ac Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 4 Aug 2021 11:08:35 -0700 Subject: [PATCH] Fix unsubscribing from observed events containing null --- src/matrix/room/ObservedEventMap.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/matrix/room/ObservedEventMap.js b/src/matrix/room/ObservedEventMap.js index 1e21df63..59f0e26a 100644 --- a/src/matrix/room/ObservedEventMap.js +++ b/src/matrix/room/ObservedEventMap.js @@ -25,7 +25,7 @@ export class ObservedEventMap { observe(eventId, eventEntry = null) { let observable = this._map.get(eventId); if (!observable) { - observable = new ObservedEvent(this, eventEntry); + observable = new ObservedEvent(this, eventEntry, eventId); this._map.set(eventId, observable); } return observable; @@ -39,8 +39,8 @@ export class ObservedEventMap { } } - _remove(observable) { - this._map.delete(observable.get().id); + _remove(id) { + this._map.delete(id); if (this._map.size === 0) { this._notifyEmpty(); } @@ -48,16 +48,17 @@ export class ObservedEventMap { } class ObservedEvent extends BaseObservableValue { - constructor(eventMap, entry) { + constructor(eventMap, entry, id) { super(); this._eventMap = eventMap; this._entry = entry; + this._id = id; // remove subscription in microtask after creating it // otherwise ObservedEvents would easily never get // removed if you never subscribe Promise.resolve().then(() => { if (!this.hasSubscriptions) { - this._eventMap.remove(this); + this._eventMap._remove(this._id); this._eventMap = null; } }); @@ -71,7 +72,7 @@ class ObservedEvent extends BaseObservableValue { } onUnsubscribeLast() { - this._eventMap._remove(this); + this._eventMap._remove(this._id); this._eventMap = null; super.onUnsubscribeLast(); }