From 39ceac95820abd168680c465feb066f80af36f20 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Fri, 4 Aug 2023 17:57:22 +0200 Subject: [PATCH] refactor next part --- .../components/refactor/ComposerCharly.svelte | 32 +++++++------------ .../{dataLoader.ts => queryLoader.ts} | 4 +-- 2 files changed, 14 insertions(+), 22 deletions(-) rename src/lib/core/refactor/{dataLoader.ts => queryLoader.ts} (79%) diff --git a/src/lib/components/refactor/ComposerCharly.svelte b/src/lib/components/refactor/ComposerCharly.svelte index a0296b1..0856da6 100644 --- a/src/lib/components/refactor/ComposerCharly.svelte +++ b/src/lib/components/refactor/ComposerCharly.svelte @@ -16,28 +16,20 @@ createMessage(messageData); } - let todos; - queryTodos.subscribe((value) => { - todos = value; - }); - - let messages; - queryMessages.subscribe((value) => { - messages = value; - }); - - $: { - const queryMap = { - todos: todos, - messages: messages - }; - - Object.entries(queryMap).forEach(([name, data]) => { - if (data) { - coreServices.mutateStore(me.id, { [name]: data }); - } + function subscribeAndMapQueries(queryMap) { + Object.entries(queryMap).forEach(([name, query]) => { + query.subscribe((value) => { + if (value) { + coreServices.mutateStore(me.id, { [name]: value }); + } + }); }); } + + subscribeAndMapQueries({ + todos: queryTodos, + messages: queryMessages + });
diff --git a/src/lib/core/refactor/dataLoader.ts b/src/lib/core/refactor/queryLoader.ts similarity index 79% rename from src/lib/core/refactor/dataLoader.ts rename to src/lib/core/refactor/queryLoader.ts index d537c26..bc542f3 100644 --- a/src/lib/core/refactor/dataLoader.ts +++ b/src/lib/core/refactor/queryLoader.ts @@ -3,7 +3,7 @@ import { writable } from 'svelte/store'; import dataSources from 'virtual:data-sources-list'; // The store that holds the data sets -export const dataStore = writable({}); +export const queryStore = writable({}); // Dynamically import the data modules and assign them to the store dataSources.forEach(src => { @@ -11,6 +11,6 @@ dataSources.forEach(src => { // Here, explicitly extract the required data or function from the module const moduleData = module[src] || module.default; - dataStore.update(store => ({ ...store, [src]: moduleData })); + queryStore.update(store => ({ ...store, [src]: moduleData })); }); }); \ No newline at end of file