File size: 516 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const activeSubs: Map<string, Map<string, boolean>> = new Map()

function getSubs(type: string) {
  let subs = activeSubs.get(type)
  if (!subs) {
    subs = new Map()
    activeSubs.set(type, subs)
  }
  return subs
}

export function subscribe(type: string, key: string) {
  getSubs(type).set(key, true)
}

export function unsubscribe(type: string, key: string) {
  const subs = getSubs(type)
  subs.delete(key)
}

export function isSubscribed(
  type: string,
  key: string,
) {
  return getSubs(type).has(key)
}