X-Git-Url: https://git.r.bdr.sh/rbdr/forum/blobdiff_plain/e749c95bf63e22ce81f8d0f933d44e0f56c24618..bd8e98d7e24c4dbaee7db6ec7955f7c2f6d396a6:/app/stores/forums.js?ds=inline diff --git a/app/stores/forums.js b/app/stores/forums.js deleted file mode 100644 index 5c7c6e6..0000000 --- a/app/stores/forums.js +++ /dev/null @@ -1,50 +0,0 @@ -import { readable } from 'svelte/store'; -import { onMessage } from '../socket_coordinator'; - -const internals = { - - // Constants - - kChangeFeedEventName: 'changefeed:forums', - - // The exported data structure - - forums: [], - - // Handles messages from the event - - handleChangeFeed(data) { - - console.log(data); - - // No old value == add - if (!data.old_val) { - console.log('Adding new data'); - 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) { - console.log(`Found old data at index ${index}`); - - 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) => { - - onMessage((message) => { - - if (message.name === internals.kChangeFeedEventName) { - internals.handleChangeFeed(message.data); - set(internals.forums); - } - }); -});