]>
git.r.bdr.sh - rbdr/forum/blob - app/stores/forums.js
5c7c6e69368eac18f93ebf6a080c9a95e4f6f18d
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
) {
20 // No old value == add
22 console
.log('Adding new data');
23 return internals
.forums
.push(data
.new_val
);
26 // We have an old value, let's find it.
27 const index
= internals
.forums
.findIndex((element
) => element
.id
=== data
.old_val
.id
);
30 console
.log(`Found old data at index ${index}`);
33 return internals
.forums
.splice(index
, 1, data
.new_val
|| undefined);
36 return internals
.forums
.splice(index
, 1);
41 export const forums
= readable(internals
.forums
, (set) => {
43 onMessage((message
) => {
45 if (message
.name
=== internals
.kChangeFeedEventName
) {
46 internals
.handleChangeFeed(message
.data
);
47 set(internals
.forums
);