Refactoring next part
This commit is contained in:
@ -1,19 +1,16 @@
|
||||
<script>
|
||||
export let me;
|
||||
export let services;
|
||||
export let store;
|
||||
export let data;
|
||||
|
||||
export let machineService;
|
||||
|
||||
let childStore;
|
||||
let childData;
|
||||
|
||||
$: if (me.do) {
|
||||
childStore = me.do.core.subscribeComposer('@ComposerBob');
|
||||
childData = me.do.core.subscribeData('@ComposerBob');
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($childStore && $childStore.machine.state) {
|
||||
me.do.machine.send($childStore.machine.state);
|
||||
if ($childData && $childData.state) {
|
||||
me.do.machine.send($childData.state);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -21,9 +18,9 @@
|
||||
<div class="p-2 border-2 border-blue-500">
|
||||
<p>My ID is: {me.id}</p>
|
||||
|
||||
I am the parent, this is my state: {$store.machine.state}
|
||||
I am the parent, this is my state: {$data.state}
|
||||
<div
|
||||
class="p-2 border-2"
|
||||
style="background-color: {$store.machine.state}; border-radius: 50%; width: 50px; height: 50px;"
|
||||
style="background-color: {$data.state}; border-radius: 50%; width: 50px; height: 50px;"
|
||||
/>
|
||||
</div>
|
||||
|
@ -1,12 +1,9 @@
|
||||
<script>
|
||||
export let me;
|
||||
export let store;
|
||||
export let machineService;
|
||||
export let data;
|
||||
|
||||
const handleButton = () => {
|
||||
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');
|
||||
}
|
||||
};
|
||||
@ -15,7 +12,7 @@
|
||||
<div class="border-2 border-yellow-500">
|
||||
<p>My ID is: {me.id}</p>
|
||||
|
||||
i am the child and this is my state: {$store.machine.state}
|
||||
i am the child and this is my state: {$data.state}
|
||||
<button
|
||||
class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700"
|
||||
on:click={handleButton}>Switch</button
|
||||
|
@ -26,6 +26,9 @@
|
||||
{
|
||||
id: 'ComposerCharly',
|
||||
component: 'ComposerCharly',
|
||||
data: {
|
||||
context: { messenges: 'put the messengesStore here' }
|
||||
},
|
||||
slot: 'aside',
|
||||
machine: {
|
||||
initial: 'NOTREADY',
|
||||
@ -43,7 +46,7 @@
|
||||
id: 'ComposerBob',
|
||||
component: 'ComposerBob',
|
||||
slot: 'top',
|
||||
store: {
|
||||
data: {
|
||||
machine: { state: 'NOTREADY' }
|
||||
},
|
||||
machine: {
|
||||
|
Reference in New Issue
Block a user