refactoring next part

This commit is contained in:
Samuel Andert
2023-08-04 13:52:37 +02:00
parent 4a01649087
commit 2e4e4bdf59
5 changed files with 79 additions and 28 deletions

View File

@ -43,12 +43,22 @@
});
}
if (composer?.machine) {
const machine = Machine({ ...composer.machine, id: composer.id });
const machine = Machine(
{
...composer.machine,
id: composer.id
},
{
services: composer.machine.services
}
);
machineService = interpret(machine).onTransition((state) => {
console.log(`${composer.id} State transitioned to: ${state.value}`);
console.log('Context:', state.context); // Log the context
getComposerStore(composer.id).update((storeValue) => ({
...storeValue,
state: state.value, // updated
context: state.context // added
state: state.value,
context: state.context
}));
});
machineService.start();
@ -58,8 +68,15 @@
if (composer?.children) {
composer.children.forEach((child) => {
if (child.machine) {
const childMachine = Machine({ ...child.machine, id: child.id });
const childMachine = Machine(
{ ...child.machine, id: child.id },
{
services: child.machine.services
}
);
machineService = interpret(childMachine).onTransition((state) => {
console.log(`${child.id} State transitioned to: ${state.value}`);
console.log('Context:', state.context); // Log the context
getComposerStore(child.id).update((storeValue) => ({
...storeValue,
state: state.value, // updated