subs: allow any object in place of the socket

This commit is contained in:
Alex Gleason 2023-08-26 15:55:16 -05:00
parent 67bba508af
commit c13b7f4af7
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 4 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import type { EventData } from '@/types.ts';
* Subscriptions can be added, removed, and matched against events.
*/
class SubscriptionStore {
#store = new Map<WebSocket, Map<string, Subscription>>();
#store = new Map<unknown, Map<string, Subscription>>();
/**
* Add a subscription to the store, and then iterate over it.
@ -20,7 +20,7 @@ class SubscriptionStore {
* }
* ```
*/
sub<K extends number>(socket: WebSocket, id: string, filters: DittoFilter<K>[]): Subscription<K> {
sub<K extends number>(socket: unknown, id: string, filters: DittoFilter<K>[]): Subscription<K> {
let subs = this.#store.get(socket);
if (!subs) {
@ -37,13 +37,13 @@ class SubscriptionStore {
}
/** Remove a subscription from the store. */
unsub(socket: WebSocket, id: string): void {
unsub(socket: unknown, id: string): void {
this.#store.get(socket)?.get(id)?.close();
this.#store.get(socket)?.delete(id);
}
/** Remove an entire socket. */
close(socket: WebSocket): void {
close(socket: unknown): void {
const subs = this.#store.get(socket);
if (subs) {