mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
make SimpleTile inherit from ViewModel
to use same update mechanism and have viewmodel infra available for tile
This commit is contained in:
parent
9745c58144
commit
cf0af775e3
@ -70,6 +70,10 @@ export class ViewModel extends EventEmitter {
|
||||
return result;
|
||||
}
|
||||
|
||||
updateOptions(options) {
|
||||
this._options = Object.assign(this._options, options);
|
||||
}
|
||||
|
||||
emitChange(changedProps) {
|
||||
if (this._options.emitChange) {
|
||||
this._options.emitChange(changedProps);
|
||||
|
@ -29,16 +29,16 @@ export class GapTile extends SimpleTile {
|
||||
// prevent doing this twice
|
||||
if (!this._loading) {
|
||||
this._loading = true;
|
||||
this.emitUpdate("isLoading");
|
||||
this.emitChange("isLoading");
|
||||
try {
|
||||
await this._timeline.fillGap(this._entry, 10);
|
||||
} catch (err) {
|
||||
console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`);
|
||||
this._error = err;
|
||||
this.emitUpdate("error");
|
||||
this.emitChange("error");
|
||||
} finally {
|
||||
this._loading = false;
|
||||
this.emitUpdate("isLoading");
|
||||
this.emitChange("isLoading");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ export class MessageTile extends SimpleTile {
|
||||
const isContinuation = prev && prev instanceof MessageTile && prev.sender === this.sender;
|
||||
if (isContinuation !== this._isContinuation) {
|
||||
this._isContinuation = isContinuation;
|
||||
this.emitUpdate("isContinuation");
|
||||
this.emitChange("isContinuation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,12 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import {UpdateAction} from "../UpdateAction.js";
|
||||
import {ViewModel} from "../../../../ViewModel.js";
|
||||
|
||||
export class SimpleTile {
|
||||
export class SimpleTile extends ViewModel {
|
||||
constructor({entry}) {
|
||||
super();
|
||||
this._entry = entry;
|
||||
this._emitUpdate = null;
|
||||
}
|
||||
// view model props for all subclasses
|
||||
// hmmm, could also do instanceof ... ?
|
||||
@ -38,12 +39,6 @@ export class SimpleTile {
|
||||
return false;
|
||||
}
|
||||
|
||||
emitUpdate(paramName) {
|
||||
if (this._emitUpdate) {
|
||||
this._emitUpdate(this, paramName);
|
||||
}
|
||||
}
|
||||
|
||||
get internalId() {
|
||||
return this._entry.asEventKey().toString();
|
||||
}
|
||||
@ -53,7 +48,7 @@ export class SimpleTile {
|
||||
}
|
||||
// TilesCollection contract below
|
||||
setUpdateEmit(emitUpdate) {
|
||||
this._emitUpdate = emitUpdate;
|
||||
this.updateOptions({emitChange: paramName => emitUpdate(this, paramName)});
|
||||
}
|
||||
|
||||
get upperEntry() {
|
||||
|
Loading…
Reference in New Issue
Block a user