feat: subscriptions

This commit is contained in:
2023-04-13 19:43:43 +01:00
parent c3c1e02ad8
commit f0c5c33c48
19 changed files with 531 additions and 58 deletions

View File

@ -179,9 +179,9 @@ export function dedupeByPubkey(events: TaggedRawEvent[]) {
return deduped.list as TaggedRawEvent[];
}
export function dedupeById(events: TaggedRawEvent[]) {
export function dedupeById<T extends { id: string }>(events: Array<T>) {
const deduped = events.reduce(
({ list, seen }: { list: TaggedRawEvent[]; seen: Set<HexKey> }, ev) => {
({ list, seen }: { list: Array<T>; seen: Set<string> }, ev) => {
if (seen.has(ev.id)) {
return { list, seen };
}
@ -193,7 +193,7 @@ export function dedupeById(events: TaggedRawEvent[]) {
},
{ list: [], seen: new Set([]) }
);
return deduped.list as TaggedRawEvent[];
return deduped.list as Array<T>;
}
/**