From 472e4e33ec48d747d0de733ea0277081be1d379e Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Thu, 3 Aug 2023 17:15:24 +0200 Subject: [PATCH] fix buggy commit --- .../components/refactor/ComposerAlice.svelte | 3 +- .../components/refactor/ComposerBob.svelte | 8 +++-- src/lib/core/refactor/Composer.svelte | 35 ++++++++----------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/lib/components/refactor/ComposerAlice.svelte b/src/lib/components/refactor/ComposerAlice.svelte index 228ba93..f41fa48 100644 --- a/src/lib/components/refactor/ComposerAlice.svelte +++ b/src/lib/components/refactor/ComposerAlice.svelte @@ -8,12 +8,11 @@ let childStore; $: if (me.do) { - childStore = me.do.core.subscribeComposer('@ComposerBob'); + childStore = me.do.subscribeComposer('@ComposerBob'); } $: { if ($childStore && $childStore.machine.state) { - console.log('ALICE machine service: ' + JSON.stringify(me.do.machine)); me.do.machine.send($childStore.machine.state); } } diff --git a/src/lib/components/refactor/ComposerBob.svelte b/src/lib/components/refactor/ComposerBob.svelte index 71f72e2..da858ec 100644 --- a/src/lib/components/refactor/ComposerBob.svelte +++ b/src/lib/components/refactor/ComposerBob.svelte @@ -4,9 +4,11 @@ export let machineService; const handleButton = () => { - console.log('BOB machine service: ' + JSON.stringify(me.do.machine)); - console.log('Sending TOGGLE event to the machine'); - me.do.machine.send('TOGGLE'); + if (me && me.do && me.do.machine) { + console.log('BOB machine service: ' + JSON.stringify(me.do.machine)); + console.log('Sending TOGGLE event to the machine'); + me.do.machine.send('TOGGLE'); + } }; diff --git a/src/lib/core/refactor/Composer.svelte b/src/lib/core/refactor/Composer.svelte index fbda03b..750face 100644 --- a/src/lib/core/refactor/Composer.svelte +++ b/src/lib/core/refactor/Composer.svelte @@ -35,12 +35,6 @@ let machineService; - let services: Record = { - core: coreServices, - machine: null - // otherFutureService: null, - }; - $: { layoutStyle = computeLayoutStyle(composer?.layout); @@ -53,30 +47,28 @@ } if (composer?.machine) { const machine = Machine({ ...composer.machine, id: composer.id }); - let composerMachineService = interpret(machine).onTransition((state) => { + machineService = interpret(machine).onTransition((state) => { getComposerStore(composer.id).update((storeValue) => ({ ...storeValue, machine: { state: state.value } })); }); - composerMachineService.start(); - composer.me.do.machine = composerMachineService; - composer.machineService = composerMachineService; + machineService.start(); + composer.machineService = machineService; } if (composer?.children) { composer.children.forEach((child) => { if (child.machine) { const childMachine = Machine({ ...child.machine, id: child.id }); - let childMachineService = interpret(childMachine).onTransition((state) => { + machineService = interpret(childMachine).onTransition((state) => { getComposerStore(child.id).update((storeValue) => ({ ...storeValue, machine: { state: state.value } })); }); - childMachineService.start(); - child.me.do.machine = childMachineService; - child.machineService = childMachineService; + machineService.start(); + child.machineService = machineService; } }); } @@ -117,16 +109,15 @@ } return FallBack; } + async function loadComponentAndService(component: IComposer) { const componentName = component.component || 'FallBack'; - let services = { - core: coreServices, - machine: component.machineService || null - // otherFutureService: null, - }; component.me = { id: component.id, - do: services + do: { + ...loadedServices.core, + machine: component.machineService || null + } }; return await getComponent(componentName); } @@ -142,6 +133,8 @@ id={composer.id} store={getComposerStore(composer.id)} machine={composer.machine} + services={loadedServices} + machineService={child.machineService} me={composer.me} /> {/await} @@ -157,6 +150,8 @@ id={child.id} store={getComposerStore(child.id)} machine={child.machine} + services={loadedServices} + machineService={child.machineService} me={child.me} /> {#if child.children && child.children.length}