forked from mystiq/hydrogen-web
WIP
This commit is contained in:
parent
a9308f69b8
commit
0dc5041f47
2 changed files with 22 additions and 3 deletions
|
@ -127,6 +127,10 @@ class Island {
|
|||
}
|
||||
}
|
||||
|
||||
export class CompareError extends Error {
|
||||
get name() { return "CompareError"; }
|
||||
}
|
||||
|
||||
/*
|
||||
index for fast lookup of how two fragments can be sorted
|
||||
*/
|
||||
|
@ -139,7 +143,7 @@ export class FragmentIdComparer {
|
|||
_getIsland(id) {
|
||||
const island = this._idToIsland.get(id);
|
||||
if (island === undefined) {
|
||||
throw new Error(`Unknown fragment id ${id}`);
|
||||
throw new CompareError(`Unknown fragment id ${id}`);
|
||||
}
|
||||
return island;
|
||||
}
|
||||
|
@ -151,7 +155,7 @@ export class FragmentIdComparer {
|
|||
const islandA = this._getIsland(idA);
|
||||
const islandB = this._getIsland(idB);
|
||||
if (islandA !== islandB) {
|
||||
throw new Error(`${idA} and ${idB} are on different islands, can't tell order`);
|
||||
throw new CompareError(`${idA} and ${idB} are on different islands, can't tell order`);
|
||||
}
|
||||
return islandA.compare(idA, idB);
|
||||
}
|
||||
|
|
|
@ -212,7 +212,22 @@ export class Timeline {
|
|||
replaceEntries(entries) {
|
||||
this._addLocalRelationsToNewRemoteEntries(entries);
|
||||
for (const entry of entries) {
|
||||
try {
|
||||
this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater);
|
||||
} catch (err) {
|
||||
if (err.name === "CompareError") {
|
||||
// see FragmentIdComparer, if the replacing entry is on a fragment
|
||||
// that is currently not loaded into the FragmentIdComparer, it will
|
||||
// throw a CompareError, and it means that the event is not loaded
|
||||
// in the timeline (like when receiving a relation for an event
|
||||
// that is not loaded in memory) so we can just drop this error as
|
||||
// replacing an event that is not already loaded is a no-op.
|
||||
continue;
|
||||
} else {
|
||||
// don't swallow other errors
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue