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