(subscription: WaveEventSubscription<T>)
| 65 | } |
| 66 | |
| 67 | function waveEventSubscribeSingle<T extends WaveEventName>(subscription: WaveEventSubscription<T>): () => void { |
| 68 | // console.log("waveEventSubscribeSingle", subscription); |
| 69 | if (subscription.handler == null) { |
| 70 | return () => {}; |
| 71 | } |
| 72 | const id: string = crypto.randomUUID(); |
| 73 | let subjects = waveEventSubjects.get(subscription.eventType); |
| 74 | if (subjects == null) { |
| 75 | subjects = []; |
| 76 | waveEventSubjects.set(subscription.eventType, subjects); |
| 77 | } |
| 78 | const subcont: WaveEventSubjectContainer = { |
| 79 | id, |
| 80 | handler: subscription.handler as (event: WaveEvent) => void, |
| 81 | scope: subscription.scope, |
| 82 | }; |
| 83 | subjects.push(subcont); |
| 84 | updateWaveEventSub(subscription.eventType); |
| 85 | return () => waveEventUnsubscribe({ id, eventType: subscription.eventType }); |
| 86 | } |
| 87 | |
| 88 | function waveEventUnsubscribe(...unsubscribes: WaveEventUnsubscribe[]) { |
| 89 | const eventTypeSet = new Set<string>(); |
no test coverage detected