(type: string, callback: (event: any) => void)
| 88 | } |
| 89 | |
| 90 | function raw(type: string, callback: (event: any) => void) { |
| 91 | log.info("subscribing", { type }) |
| 92 | const subscriptions = state().subscriptions |
| 93 | let match = subscriptions.get(type) ?? [] |
| 94 | match.push(callback) |
| 95 | subscriptions.set(type, match) |
| 96 | |
| 97 | return () => { |
| 98 | log.info("unsubscribing", { type }) |
| 99 | const match = subscriptions.get(type) |
| 100 | if (!match) return |
| 101 | const index = match.indexOf(callback) |
| 102 | if (index === -1) return |
| 103 | match.splice(index, 1) |
| 104 | } |
| 105 | } |
| 106 | } |