]>
git.r.bdr.sh - rbdr/forum/blob - app/stores/forums.js
e82616369b5431aa797e897a80e8edbaa1d6d14e
1 import { readable
} from 'svelte/store';
2 import { onMessage
} from '../socket_coordinator';
8 kChangeFeedEventName: 'changefeed:forums',
10 // The exported data structure
14 // Handles messages from the event
16 handleChangeFeed(data
) {
18 // No old value == add
20 return internals
.forums
.push(data
.new_val
);
23 // We have an old value, let's find it.
24 const index
= internals
.forums
.findIndex((element
) => element
.id
=== data
.old_val
.id
);
28 return internals
.forums
.splice(index
, 1, data
.new_val
|| undefined);
31 return internals
.forums
.splice(index
, 1);
36 export const forums
= readable(internals
.forums
, (set) => {
38 onMessage((message
) => {
40 if (message
.name
=== internals
.kChangeFeedEventName
) {
41 internals
.handleChangeFeed(message
.data
);
42 set(internals
.forums
);