forked from mystiq/hydrogen-web
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:
parent
139a87de99
commit
6beff7e552
2 changed files with 11 additions and 6 deletions
|
@ -35,7 +35,7 @@ export class TilesCollection extends BaseObservableList {
|
|||
_createTile(entry) {
|
||||
const Tile = this._tileOptions.tileClassForEntry(entry);
|
||||
if (Tile) {
|
||||
return new Tile(entry, { ...this._tileOptions });
|
||||
return new Tile(entry, this._tileOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ export class SimpleTile extends ViewModel {
|
|||
constructor(entry, options) {
|
||||
super(options);
|
||||
this._entry = entry;
|
||||
this._emitUpdate = undefined;
|
||||
}
|
||||
// view model props for all subclasses
|
||||
// hmmm, could also do instanceof ... ?
|
||||
|
@ -67,16 +68,20 @@ export class SimpleTile extends ViewModel {
|
|||
|
||||
// TilesCollection contract below
|
||||
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
|
||||
// we switched away from the room and the response
|
||||
// comes in, triggering an emitChange in a tile that
|
||||
// has been disposed already (and hence the change
|
||||
// callback has been cleared by dispose) We should just ignore this.
|
||||
if (emitUpdate) {
|
||||
emitUpdate(this, paramName);
|
||||
this._emitUpdate(this, changedProps);
|
||||
}
|
||||
}});
|
||||
super.emitChange(changedProps);
|
||||
}
|
||||
|
||||
get upperEntry() {
|
||||
|
|
Loading…
Reference in a new issue