[#3789] Destroy mutable objects only if needed (#3799)

* [#3789] Don't observe objects if they are already mutable objects. Add some null checks.
* Don't destroy mutable in Selection.js if it wasn't created in that context.
* Remove * listeners and add null checks
* Don't delete _observers and _globalEventEmitters on $destroy. Pop all items off the _observers list for a mutable domain object.

Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Shefali Joshi
2021-04-20 16:47:36 -07:00
committed by GitHub
parent 8157cdc7e9
commit 9fa71244ea
7 changed files with 43 additions and 30 deletions

View File

@ -112,9 +112,11 @@ class MutableDomainObject {
return () => this._instanceEventEmitter.off(event, callback);
}
$destroy() {
this._observers.forEach(observer => observer());
delete this._globalEventEmitter;
delete this._observers;
while (this._observers.length > 0) {
const observer = this._observers.pop();
observer();
}
this._instanceEventEmitter.emit('$_destroy');
}