service.subscribe
- don't send event for initializing machine
#1275
Replies: 2 comments 7 replies
-
The first thing that I would try would be to save the state without any events attached to it at all. If you |
Beta Was this translation helpful? Give feedback.
-
Try Also, I'd avoid relying on implementation details ( In summary:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I've written my own
useEventMachine
-hook based onuseMachine
which should care about starting with the correct state, save events to an event store and initializing the machine.To save events I'm using
service.subscribe
, so far so good.But when restoring the state a change is triggered for subscribing which leads to the event be saved. This leads to many redundant events when reloading the page quite often. For the initial state I filter for
state.event.type === 'xstate.init'
in my save event function, but for restoring the state I don't know if there is any way to identify if this event was user/internal triggered or from the restoring of the state.Do you have any suggestions?
I also tried to wrap the
service.subscribe
in a timeout, but unfortunately that doesn't work either.Beta Was this translation helpful? Give feedback.
All reactions