Compare commits

...
This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.

15 commits

Author SHA1 Message Date
RMidhunSuresh
dab3ba9f74 Update comment 2021-11-03 14:17:12 +05:30
RMidhunSuresh
d0b34ef2ca Use flags to work around race 2021-11-03 13:56:21 +05:30
RMidhunSuresh
e94a9b36b3 Do not call hasSeenUpdate onUpdate
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-29 12:16:22 +05:30
RMidhunSuresh
f662a25c8b Fix bug
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-28 14:47:24 +05:30
RMidhunSuresh
60a92cf6b7 Limit recursion
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-28 12:14:58 +05:30
RMidhunSuresh
b2a8b243ec Add explaining comment
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-28 12:05:16 +05:30
RMidhunSuresh
a8a04d4036 Enclose in try..finally
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-28 12:00:22 +05:30
RMidhunSuresh
7e8c0109ae Add explaining comment
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-28 11:57:18 +05:30
RMidhunSuresh
b979e11ef5 Support onReset and onMove
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-28 11:44:09 +05:30
RMidhunSuresh
20616f5983 Rename variable
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-27 12:38:55 +05:30
RMidhunSuresh
345560ed97 Rename ret to gapPromise
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-27 12:28:12 +05:30
RMidhunSuresh
57fa292583 No need to filter top tile out
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-27 12:26:48 +05:30
RMidhunSuresh
177ef43ebf Remove leak
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-27 11:03:34 +05:30
RMidhunSuresh
ebafd8c42b Remove debug code
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-26 14:29:03 +05:30
RMidhunSuresh
b648b87687 Brainstorm code
Signed-off-by: RMidhunSuresh <hi@midhun.dev>
2021-10-26 12:12:58 +05:30
2 changed files with 59 additions and 2 deletions

View file

@ -47,6 +47,58 @@ export class TimelineViewModel extends ViewModel {
this._requestedEndTile = null; this._requestedEndTile = null;
this._requestScheduled = false; this._requestScheduled = false;
this._showJumpDown = false; this._showJumpDown = false;
this._watchMap = new WeakMap();
}
async watchForGapFill(gapPromise, gapTile, depth = 0) {
this._watchMap.set(gapTile, true);
if (depth >= 10) {
console.error("watchForGapFill exceeded a recursive depth of 10");
return;
}
let hasSeenUpdate = false;
const checkForUpdate = (idx, tile) => {
if (tile.shape !== "gap") {
/*
It's possible that this method executes before the GapTile has been rendered,
so don't count the GapTile as an update.
Usually happens when onScroll() is triggered by a non-timeline UI change,
eg: SessionStatusView being rendered
*/
hasSeenUpdate = true;
}
}
const subscription = {
onAdd: (idx, tile) => checkForUpdate(idx, tile),
onRemove: (idx, tile) => checkForUpdate(idx, tile),
onUpdate: () => { /* shouldn't be called */ },
onMove: () => { /* shouldn't be called */ },
onReset: () => { /* shouldn't be called */ }
};
this.tiles.subscribe(subscription);
let gapResult;
try {
gapResult = await gapPromise;
}
finally {
this.tiles.unsubscribe(subscription);
}
if (!gapResult) {
/*
If gapResult resolves to false, then the gap is already being filled
and is thus being tracked for updates by a previous invocation of this method
*/
this._watchMap.set(gapTile, false);
return;
}
/*
We may have seen an update, but did the corresponding call to watchForGapFill from
that update already return?
*/
const hasNextInvocationReturned = !this._watchMap.get(gapTile);
if (!hasSeenUpdate || hasNextInvocationReturned) {
this.watchForGapFill(gapTile.notifyVisible(), gapTile, depth + 1);
}
} }
/** if this.tiles is empty, call this with undefined for both startTile and endTile */ /** if this.tiles is empty, call this with undefined for both startTile and endTile */
@ -73,7 +125,10 @@ export class TimelineViewModel extends ViewModel {
const startIndex = this._tiles.getTileIndex(this._startTile); const startIndex = this._tiles.getTileIndex(this._startTile);
const endIndex = this._tiles.getTileIndex(this._endTile); const endIndex = this._tiles.getTileIndex(this._endTile);
for (const tile of this._tiles.sliceIterator(startIndex, endIndex + 1)) { for (const tile of this._tiles.sliceIterator(startIndex, endIndex + 1)) {
tile.notifyVisible(); const gapPromise = tile.notifyVisible();
if (gapPromise) {
this.watchForGapFill(gapPromise, tile);
}
} }
loadTop = startIndex < 10; loadTop = startIndex < 10;
this._setShowJumpDown(endIndex < (this._tiles.length - 1)); this._setShowJumpDown(endIndex < (this._tiles.length - 1));

View file

@ -42,11 +42,13 @@ export class GapTile extends SimpleTile {
this._loading = false; this._loading = false;
this.emitChange("isLoading"); this.emitChange("isLoading");
} }
return true;
} }
return false;
} }
notifyVisible() { notifyVisible() {
this.fill(); return this.fill();
} }
get isAtTop() { get isAtTop() {