override emitChange so no need to clone option object for all tiles

instead, we don't store the emitChange in the options but rather on
the tile itself.
This commit is contained in:
Bruno Windels 2022-05-09 14:09:45 +02:00
parent 139a87de99
commit 6beff7e552
2 changed files with 11 additions and 6 deletions

View file

@ -35,7 +35,7 @@ export class TilesCollection extends BaseObservableList {
_createTile(entry) { _createTile(entry) {
const Tile = this._tileOptions.tileClassForEntry(entry); const Tile = this._tileOptions.tileClassForEntry(entry);
if (Tile) { if (Tile) {
return new Tile(entry, { ...this._tileOptions }); return new Tile(entry, this._tileOptions);
} }
} }

View file

@ -22,6 +22,7 @@ export class SimpleTile extends ViewModel {
constructor(entry, options) { constructor(entry, options) {
super(options); super(options);
this._entry = entry; this._entry = entry;
this._emitUpdate = undefined;
} }
// view model props for all subclasses // view model props for all subclasses
// hmmm, could also do instanceof ... ? // hmmm, could also do instanceof ... ?
@ -67,16 +68,20 @@ export class SimpleTile extends ViewModel {
// TilesCollection contract below // TilesCollection contract below
setUpdateEmit(emitUpdate) { setUpdateEmit(emitUpdate) {
this.updateOptions({emitChange: paramName => { this._emitUpdate = emitUpdate;
}
/** overrides the emitChange in ViewModel to also emit the update over the tiles collection */
emitChange(changedProps) {
if (this._emitUpdate) {
// it can happen that after some network call // it can happen that after some network call
// we switched away from the room and the response // we switched away from the room and the response
// comes in, triggering an emitChange in a tile that // comes in, triggering an emitChange in a tile that
// has been disposed already (and hence the change // has been disposed already (and hence the change
// callback has been cleared by dispose) We should just ignore this. // callback has been cleared by dispose) We should just ignore this.
if (emitUpdate) { this._emitUpdate(this, changedProps);
emitUpdate(this, paramName); }
} super.emitChange(changedProps);
}});
} }
get upperEntry() { get upperEntry() {