summaryrefslogtreecommitdiff
path: root/ui/lib/state/remote/channels.svelte.js
blob: 64edb09da3ca120b916eebe18a511cb84bb54399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { SvelteMap } from 'svelte/reactivity';

export class Channels {
  all = $state();

  static boot(channels) {
    const all = new SvelteMap(channels.map((channel) => [channel.id, channel]));
    return new Channels({ all });
  }

  constructor({ all }) {
    this.all = all;
  }

  add({ id, name }) {
    this.all.set(id, { id, name });
  }

  remove(id) {
    this.all.delete(id);
  }
}