refactor next part

This commit is contained in:
Samuel Andert 2023-08-04 17:57:22 +02:00
parent 8214792f01
commit 39ceac9582
2 changed files with 14 additions and 22 deletions

View File

@ -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
});
</script>
<div class="flex flex-col h-screen">

View File

@ -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 }));
});
});