feat: redux timeline cache

This commit is contained in:
2023-02-21 14:35:53 +00:00
parent a49121c05a
commit e6f64e9b9e
6 changed files with 160 additions and 69 deletions

View File

@ -177,6 +177,23 @@ export function dedupeByPubkey(events: TaggedRawEvent[]) {
return deduped.list as TaggedRawEvent[];
}
export function dedupeById(events: TaggedRawEvent[]) {
const deduped = events.reduce(
({ list, seen }: { list: TaggedRawEvent[]; seen: Set<HexKey> }, ev) => {
if (seen.has(ev.id)) {
return { list, seen };
}
seen.add(ev.id);
return {
seen,
list: [...list, ev],
};
},
{ list: [], seen: new Set([]) }
);
return deduped.list as TaggedRawEvent[];
}
export function unwrap<T>(v: T | undefined | null): T {
if (v === undefined || v === null) {
throw new Error("missing value");