forked from mystiq/hydrogen-web
Merge pull request #731 from vector-im/fix-tilescollection
Newly created tiles must be given a copy of tilesOptions
This commit is contained in:
commit
a06474d7ac
2 changed files with 13 additions and 12 deletions
|
@ -40,9 +40,9 @@ export type Options = {
|
|||
export class ViewModel<O extends Options = Options> extends EventEmitter<{change: never}> {
|
||||
private disposables?: Disposables;
|
||||
private _isDisposed = false;
|
||||
private _options: O;
|
||||
private _options: Readonly<O>;
|
||||
|
||||
constructor(options: O) {
|
||||
constructor(options: Readonly<O>) {
|
||||
super();
|
||||
this._options = options;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
|||
return Object.assign({}, this._options, explicitOptions);
|
||||
}
|
||||
|
||||
get options(): O { return this._options; }
|
||||
get options(): Readonly<O> { return this._options; }
|
||||
|
||||
// makes it easier to pass through dependencies of a sub-view model
|
||||
getOption<N extends keyof O>(name: N): O[N] {
|
||||
|
@ -115,10 +115,6 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
|||
return result;
|
||||
}
|
||||
|
||||
updateOptions(options: O): void {
|
||||
this._options = Object.assign(this._options, options);
|
||||
}
|
||||
|
||||
emitChange(changedProps: any): void {
|
||||
if (this._options.emitChange) {
|
||||
this._options.emitChange(changedProps);
|
||||
|
|
|
@ -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