-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
req: Allow access to internal service #9
Comments
@brunocangs any thoughts? |
We have the actor/service available on the internal
const machineAtom = atomWithMachine(...)
const actorAtom = actorFromMachine(machineAtom)
@lxcid What you need is to be able to call the Edit: Thinking about it some more, the best way would probably be to decouple the logic, and make each piece along the setup process available to consume separately. That way we don't lose compatibility with the current API.
If you think this is a good path, I can look for some time during this week to try to implement it Footnotes |
thank you for considering. generally. a machine is like a configuration and an actor is an instance of the configuration and store the state. sometimes we want to listen to state transition, thus the on() call or onTransition() think of machine instance as some kind of observable. able to receive event and changes accordingly. if i want i can listen to changes to state, but i thought naturally it might make sense to listen to transition from the machine instance. your proposal sounds great. if i can control each step of the step, i can have more control over it. |
I've been building a global shopping cart machine for an app and was having issues with reactivity when an event triggered a state change of my machine. My components were not re-rendering. I need to try to put together a simple reproduction of that issue. It may have to do with the state also invoking an actor. Anyway... while looking at the code here and reading @xstate/react, I decided to try an alternate implementation that seems to be working for me that I called I took inspiration from @xstate/react's createActorContext code. It uses I added a So instead of component code like this: const [state, send] = useAtom(machineAtom); It works like this with an atom created with const [actorRef] = useAtom(machineAtom);
const state = useSnapshot(machineAtom); Instead of |
Sorry -- I know this is off-topic for this issue, but just to follow up to my previous post -- I found a similar issue with useSelector not triggering rerenders. My states with an invoked actor are calling a server function in React 19 (with Waku). One of the actors works fine but the other seems to not allow react to update until the server function is finished being called and that seems to be preventing the snapshot update. I wasn't able to reproduce with a simpler example with just xstate and client side react. I need to keep working on that (and will open another issue here or upstream if I can track it down). I did find a hack to workaround the issue - using setTimeout with a 0 timeout and calling my server function within the callback function: const res = await new Promise<
Awaited<ReturnType<typeof serverFunction>>
>((resolve) =>
setTimeout(async () => {
console.log("sending server function request");
const _res = await serverFunction(params);
console.log("finished server function request");
resolve(_res);
}, 0)
); When I invoke my server function within my |
@lxcid @rmarscher We've just released |
Is it possible for services to be exposed or accessible.
This allow us to hook up listeners post initialization.
The text was updated successfully, but these errors were encountered: