adjust tiles(collection) to entry changes

This commit is contained in:
Bruno Windels 2019-06-01 18:29:02 +02:00
parent 35d90a8535
commit 039bbe038c
5 changed files with 25 additions and 23 deletions

View file

@ -1,7 +1,7 @@
import BaseObservableList from "../../../../observable/list/BaseObservableList.js";
import sortedIndex from "../../../../utils/sortedIndex.js";
// maps 1..n entries to 0..1 tile. Entries are what is stored in the timeline, either an event or gap
// maps 1..n entries to 0..1 tile. Entries are what is stored in the timeline, either an event or fragmentboundary
export default class TilesCollection extends BaseObservableList {
constructor(entries, tileCreator) {
super();
@ -39,16 +39,16 @@ export default class TilesCollection extends BaseObservableList {
}
}
_findTileIdx(sortKey) {
return sortedIndex(this._tiles, sortKey, (key, tile) => {
_findTileIdx(entry) {
return sortedIndex(this._tiles, entry, (entry, tile) => {
// negate result because we're switching the order of the params
return -tile.compareSortKey(key);
return -tile.compareEntry(entry);
});
}
_findTileAtIdx(sortKey, idx) {
_findTileAtIdx(entry, idx) {
const tile = this._getTileAtIdx(idx);
if (tile && tile.compareSortKey(sortKey) === 0) {
if (tile && tile.compareEntry(entry) === 0) {
return tile;
}
}
@ -72,8 +72,7 @@ export default class TilesCollection extends BaseObservableList {
}
onAdd(index, entry) {
const {sortKey} = entry;
const tileIdx = this._findTileIdx(sortKey);
const tileIdx = this._findTileIdx(entry);
const prevTile = this._getTileAtIdx(tileIdx - 1);
if (prevTile && prevTile.tryIncludeEntry(entry)) {
this.emitUpdate(tileIdx - 1, prevTile);
@ -98,9 +97,8 @@ export default class TilesCollection extends BaseObservableList {
}
onUpdate(index, entry, params) {
const {sortKey} = entry;
const tileIdx = this._findTileIdx(sortKey);
const tile = this._findTileAtIdx(sortKey, tileIdx);
const tileIdx = this._findTileIdx(entry);
const tile = this._findTileAtIdx(entry, tileIdx);
if (tile) {
const newParams = tile.updateEntry(entry, params);
if (newParams) {
@ -122,9 +120,8 @@ export default class TilesCollection extends BaseObservableList {
// would also be called when unloading a part of the timeline
onRemove(index, entry) {
const {sortKey} = entry;
const tileIdx = this._findTileIdx(sortKey);
const tile = this._findTileAtIdx(sortKey, tileIdx);
const tileIdx = this._findTileIdx(entry);
const tile = this._findTileAtIdx(entry, tileIdx);
if (tile) {
const removeTile = tile.removeEntry(entry);
if (removeTile) {

View file

@ -29,7 +29,7 @@ export default class GapTile extends SimpleTile {
}
get direction() {
return this._entry.prev_batch ? "backward" : "forward";
return this._entry.direction;
}
get error() {

View file

@ -18,18 +18,19 @@ export default class SimpleTile {
get hasDateSeparator() {
return false;
}
get upperSortKey() {
return this._entry.sortKey;
// TilesCollection contract? unused atm
get upperEntry() {
return this._entry;
}
get lowerSortKey() {
return this._entry.sortKey;
// TilesCollection contract? unused atm
get lowerEntry() {
return this._entry;
}
// TilesCollection contract
compareSortKey(key) {
return this._entry.sortKey.compare(key);
compareEntry(entry) {
return this._entry.compare(entry);
}
// update received for already included (falls within sort keys) entry

View file

@ -8,7 +8,7 @@ import RoomMemberTile from "./tiles/RoomMemberTile.js";
export default function ({timeline, emitUpdate}) {
return function tilesCreator(entry) {
const options = {entry, emitUpdate};
if (entry.gap) {
if (entry.isGap) {
return new GapTile(options, timeline);
} else if (entry.event) {
const event = entry.event;

View file

@ -18,6 +18,10 @@ export default class EventEntry extends BaseEntry {
return this._eventEntry.event.content;
}
get event() {
return this._eventEntry.event;
}
get type() {
return this._eventEntry.event.type;
}