aboutsummaryrefslogtreecommitdiff
path: root/src/stores/forums.js
blob: e7acb606cf536db7f227018da308eff532a3136f (plain)
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
28
29
30
31
32
33
34
35
36
import { readable } from 'svelte/store';

const internals = {

  // Constants

  kChangeFeedEventName: 'changefeed:forums',

  // The exported data structure

  forums: [],

  // Handles messages from the event

  handleChangeFeed(data) {

    // No old value == add
    if (!data.old_val) {
      return internals.forums.push(data.new_val);
    }

    // We have an old value, let's find it.
    const index = internals.forums.findIndex((element) => element.id === data.old_val.id);

    if (index > -1) {
      if (data.new_val) {
        return internals.forums.splice(index, 1, data.new_val || undefined);
      }

      return internals.forums.splice(index, 1);
    }
  }
};

export const forums = readable(internals.forums, (set) => {
});