From 3362d96b849ef36c430a8bcd86cbe082868cecfb Mon Sep 17 00:00:00 2001 From: penpenpng Date: Mon, 4 Dec 2023 05:19:03 +0900 Subject: [PATCH] feat: fix `tie()` --- src/__test__/operator.test.ts | 6 ++++++ src/operator.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/__test__/operator.test.ts b/src/__test__/operator.test.ts index 4802960..115737f 100644 --- a/src/__test__/operator.test.ts +++ b/src/__test__/operator.test.ts @@ -93,22 +93,27 @@ test("tie()", async () => { { ...packets[0], seenOn: ["wss://aaa.example.com"], + isNew: true, }, { ...packets[2], seenOn: ["wss://aaa.example.com"], + isNew: true, }, { ...packets[3], seenOn: ["wss://aaa.example.com"], + isNew: true, }, { ...packets[4], seenOn: ["wss://aaa.example.com", "wss://bbb.example.com"], + isNew: false, }, { ...packets[5], seenOn: ["wss://aaa.example.com", "wss://bbb.example.com"], + isNew: false, }, { ...packets[6], @@ -117,6 +122,7 @@ test("tie()", async () => { "wss://bbb.example.com", "wss://ccc.example.com", ], + isNew: false, } ) ); diff --git a/src/operator.ts b/src/operator.ts index 5f5c167..c29aefe 100644 --- a/src/operator.ts +++ b/src/operator.ts @@ -101,7 +101,7 @@ export function tie

( * Create a customizable tie operator. */ export function createTie

(): [ - OperatorFunction }>, + OperatorFunction; isNew: boolean }>, Map> ] { const memo = new Map>(); @@ -111,6 +111,7 @@ export function createTie

(): [ filter((packet) => !memo.get(packet.event.id)?.has(packet.from)), map((packet) => { const seenOn = memo.get(packet.event.id) ?? new Set(); + const isNew = seenOn.size <= 0; seenOn.add(packet.from); memo.set(packet.event.id, seenOn); @@ -118,6 +119,7 @@ export function createTie

(): [ return { ...packet, seenOn, + isNew, }; }) ),