fix buggy commit

This commit is contained in:
Samuel Andert 2023-08-03 17:15:24 +02:00
parent c9be693408
commit 472e4e33ec
3 changed files with 21 additions and 25 deletions

View File

@ -8,12 +8,11 @@
let childStore; let childStore;
$: if (me.do) { $: if (me.do) {
childStore = me.do.core.subscribeComposer('@ComposerBob'); childStore = me.do.subscribeComposer('@ComposerBob');
} }
$: { $: {
if ($childStore && $childStore.machine.state) { if ($childStore && $childStore.machine.state) {
console.log('ALICE machine service: ' + JSON.stringify(me.do.machine));
me.do.machine.send($childStore.machine.state); me.do.machine.send($childStore.machine.state);
} }
} }

View File

@ -4,9 +4,11 @@
export let machineService; export let machineService;
const handleButton = () => { const handleButton = () => {
if (me && me.do && me.do.machine) {
console.log('BOB machine service: ' + JSON.stringify(me.do.machine)); console.log('BOB machine service: ' + JSON.stringify(me.do.machine));
console.log('Sending TOGGLE event to the machine'); console.log('Sending TOGGLE event to the machine');
me.do.machine.send('TOGGLE'); me.do.machine.send('TOGGLE');
}
}; };
</script> </script>

View File

@ -35,12 +35,6 @@
let machineService; let machineService;
let services: Record<string, any> = {
core: coreServices,
machine: null
// otherFutureService: null,
};
$: { $: {
layoutStyle = computeLayoutStyle(composer?.layout); layoutStyle = computeLayoutStyle(composer?.layout);
@ -53,30 +47,28 @@
} }
if (composer?.machine) { if (composer?.machine) {
const machine = Machine({ ...composer.machine, id: composer.id }); const machine = Machine({ ...composer.machine, id: composer.id });
let composerMachineService = interpret(machine).onTransition((state) => { machineService = interpret(machine).onTransition((state) => {
getComposerStore(composer.id).update((storeValue) => ({ getComposerStore(composer.id).update((storeValue) => ({
...storeValue, ...storeValue,
machine: { state: state.value } machine: { state: state.value }
})); }));
}); });
composerMachineService.start(); machineService.start();
composer.me.do.machine = composerMachineService; composer.machineService = machineService;
composer.machineService = composerMachineService;
} }
if (composer?.children) { if (composer?.children) {
composer.children.forEach((child) => { composer.children.forEach((child) => {
if (child.machine) { if (child.machine) {
const childMachine = Machine({ ...child.machine, id: child.id }); const childMachine = Machine({ ...child.machine, id: child.id });
let childMachineService = interpret(childMachine).onTransition((state) => { machineService = interpret(childMachine).onTransition((state) => {
getComposerStore(child.id).update((storeValue) => ({ getComposerStore(child.id).update((storeValue) => ({
...storeValue, ...storeValue,
machine: { state: state.value } machine: { state: state.value }
})); }));
}); });
childMachineService.start(); machineService.start();
child.me.do.machine = childMachineService; child.machineService = machineService;
child.machineService = childMachineService;
} }
}); });
} }
@ -117,16 +109,15 @@
} }
return FallBack; return FallBack;
} }
async function loadComponentAndService(component: IComposer) { async function loadComponentAndService(component: IComposer) {
const componentName = component.component || 'FallBack'; const componentName = component.component || 'FallBack';
let services = {
core: coreServices,
machine: component.machineService || null
// otherFutureService: null,
};
component.me = { component.me = {
id: component.id, id: component.id,
do: services do: {
...loadedServices.core,
machine: component.machineService || null
}
}; };
return await getComponent(componentName); return await getComponent(componentName);
} }
@ -142,6 +133,8 @@
id={composer.id} id={composer.id}
store={getComposerStore(composer.id)} store={getComposerStore(composer.id)}
machine={composer.machine} machine={composer.machine}
services={loadedServices}
machineService={child.machineService}
me={composer.me} me={composer.me}
/> />
{/await} {/await}
@ -157,6 +150,8 @@
id={child.id} id={child.id}
store={getComposerStore(child.id)} store={getComposerStore(child.id)}
machine={child.machine} machine={child.machine}
services={loadedServices}
machineService={child.machineService}
me={child.me} me={child.me}
/> />
{#if child.children && child.children.length} {#if child.children && child.children.length}