mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateOptions(options) {
|
||||||
|
this._options = Object.assign(this._options, options);
|
||||||
|
}
|
||||||
|
|
||||||
emitChange(changedProps) {
|
emitChange(changedProps) {
|
||||||
if (this._options.emitChange) {
|
if (this._options.emitChange) {
|
||||||
this._options.emitChange(changedProps);
|
this._options.emitChange(changedProps);
|
||||||
|
@ -29,16 +29,16 @@ export class GapTile extends SimpleTile {
|
|||||||
// prevent doing this twice
|
// prevent doing this twice
|
||||||
if (!this._loading) {
|
if (!this._loading) {
|
||||||
this._loading = true;
|
this._loading = true;
|
||||||
this.emitUpdate("isLoading");
|
this.emitChange("isLoading");
|
||||||
try {
|
try {
|
||||||
await this._timeline.fillGap(this._entry, 10);
|
await this._timeline.fillGap(this._entry, 10);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`);
|
console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`);
|
||||||
this._error = err;
|
this._error = err;
|
||||||
this.emitUpdate("error");
|
this.emitChange("error");
|
||||||
} finally {
|
} finally {
|
||||||
this._loading = false;
|
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;
|
const isContinuation = prev && prev instanceof MessageTile && prev.sender === this.sender;
|
||||||
if (isContinuation !== this._isContinuation) {
|
if (isContinuation !== this._isContinuation) {
|
||||||
this._isContinuation = isContinuation;
|
this._isContinuation = isContinuation;
|
||||||
this.emitUpdate("isContinuation");
|
this.emitChange("isContinuation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,12 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {UpdateAction} from "../UpdateAction.js";
|
import {UpdateAction} from "../UpdateAction.js";
|
||||||
|
import {ViewModel} from "../../../../ViewModel.js";
|
||||||
|
|
||||||
export class SimpleTile {
|
export class SimpleTile extends ViewModel {
|
||||||
constructor({entry}) {
|
constructor({entry}) {
|
||||||
|
super();
|
||||||
this._entry = entry;
|
this._entry = entry;
|
||||||
this._emitUpdate = null;
|
|
||||||
}
|
}
|
||||||
// view model props for all subclasses
|
// view model props for all subclasses
|
||||||
// hmmm, could also do instanceof ... ?
|
// hmmm, could also do instanceof ... ?
|
||||||
@ -38,12 +39,6 @@ export class SimpleTile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
emitUpdate(paramName) {
|
|
||||||
if (this._emitUpdate) {
|
|
||||||
this._emitUpdate(this, paramName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get internalId() {
|
get internalId() {
|
||||||
return this._entry.asEventKey().toString();
|
return this._entry.asEventKey().toString();
|
||||||
}
|
}
|
||||||
@ -53,7 +48,7 @@ export class SimpleTile {
|
|||||||
}
|
}
|
||||||
// TilesCollection contract below
|
// TilesCollection contract below
|
||||||
setUpdateEmit(emitUpdate) {
|
setUpdateEmit(emitUpdate) {
|
||||||
this._emitUpdate = emitUpdate;
|
this.updateOptions({emitChange: paramName => emitUpdate(this, paramName)});
|
||||||
}
|
}
|
||||||
|
|
||||||
get upperEntry() {
|
get upperEntry() {
|
||||||
|
Loading…
Reference in New Issue
Block a user