Replies: 2 comments
-
Why did you want to avoid using |
Beta Was this translation helpful? Give feedback.
-
I wanted to avoid that kind of tight coupling. And more practically, making the coupling obvious, when I tried to use the socket machine standalone, it threw an error because there was no parent. Currently, I am using the socket from the machine but via children.socketService of appMachine, see https://codesandbox.io/p/devbox/brave-paper-fns5sv?file=%2Fsrc%2Fhooks%2FuseSocketService.ts so effectively I already gave in and accepted that there is a strict hierarchy and socketMachine can't be used standalone anyways. And of course I don't want a new socket client+connection each time a component uses the socket, so it was a conceptual mistake on my side about how use machine works. I hope this makes sense :) |
Beta Was this translation helpful? Give feedback.
-
This is in regards to the response on #4906 by @davidkpiano, which I found when searching for a specific problem around history, but .. well it made me doubt my current approach more generally 😄
How would you integrate a socket connection machine into a "higher-level" app machine?
Let's say there's an appMachine that has "initial", "connected" and "disconnected" states (and some more of course), and it "uses" a socketMachine with its own flows as, for example, a "socketService". How would you make appMachine transition to its own "connected" state when socketMachine is connected?
How would you transition appMachine to its "disconnected" state, remembering the old state and allowing it to go back there when socketMachine is connected again?
After some struggle and trial and error, I ended up with a somewhat weird setup:
(All this to avoid sendParent from the socket machine, for a few reasons. Maybe i should have done it that way in the first place...)
I guess there's no good way of showcasing how two machines work together in studio as of now..?
I tried to bring my local project to codesandbox, and while I got the code there.. it doesn't work 😄
weird errors.. but the approach is readable I guess: https://codesandbox.io/p/devbox/brave-paper-fns5sv
Here's the socket machine in studio: https://stately.ai/registry/editor/bcdb9758-377c-47e2-916f-dcbdb5377b73?machineId=8085e6cf-40e5-4136-90ed-646863bc439f&mode=Design
And here's the appMachine, completely looking broken in studio 😆 : https://stately.ai/registry/editor/bcdb9758-377c-47e2-916f-dcbdb5377b73?machineId=d8ffc128-f5a2-4af6-b38e-ebe5be96bcba&mode=design
Now, getting some kind of review and flaws or misconceptions pointed out is great, but what I'd love even more is a "properly done" example with v5..
Beta Was this translation helpful? Give feedback.
All reactions