moveing dynamic svelte store queries to xstate

This commit is contained in:
Samuel Andert 2023-08-04 18:23:36 +02:00
parent 39ceac9582
commit 9bb780cd96
2 changed files with 22 additions and 25 deletions

View File

@ -1,7 +1,4 @@
<script>
import { coreServices } from '$lib/core/refactor/coreServices';
import { queryMessages } from '$lib/data/queryMessages';
import { queryTodos } from '$lib/data/queryTodos';
import { createMessage } from '$lib/services/messages/messages';
export let me;
export let data;
@ -15,21 +12,6 @@
};
createMessage(messageData);
}
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

@ -1,9 +1,8 @@
<script lang="ts">
import Composer from '$lib/core/refactor/Composer.svelte';
import { assign } from 'xstate';
import { queryMessages } from '$lib/data/queryMessages';
import { get } from 'svelte/store';
import { coreServices } from '$lib/core/refactor/coreServices';
import { queryTodos } from '$lib/data/queryTodos';
let composer = {
id: 'ComposerParent',
@ -31,15 +30,31 @@
id: 'ComposerCharly',
component: 'ComposerCharly',
slot: 'aside',
// data: {
// queries: {
// todos: queryTodos,
// messages: queryMessages
// }
// },
machine: {
initial: 'LOADING',
// context: {
// hello: 'start',
// messages: []
// },
states: {
LOADING: {
entry: () => {},
entry: () => {
function subscribeAndMapQueries(queryMap) {
Object.entries(queryMap).forEach(([name, query]) => {
query.subscribe((value) => {
if (value) {
coreServices.mutateStore('ComposerCharly', { [name]: value });
}
});
});
}
return subscribeAndMapQueries({
todos: queryTodos,
messages: queryMessages
});
},
on: {
TOGGLE: {
target: 'READY'