Curious if I'm running headlong into an antipattern here in my first try with xstate, specifically around the idea that actions are "fire-and-forget side-effects". Wondering what the boundaries are of that advice. I'm modeling an engine for a CLI as a state machine actor which bootstraps with an entry action on the initial state, which will eventually cause a transition to be fired. The way I've gotten this working so far is to use enqueueActions in the following manner:
actions: {
"checkStore": enqueueActions(({ enqueue }) => {
console.log("Checking store");
const checkStoreResult = 'foo';
enqueue.raise(() => ({ type: 'storeChecked', data: checkStoreResult }));
}),
My initial impulse was to define checkStore as an arbitrary function which would do stuff and then call raise itself when read, or perhaps to give that function a reference to the actor so it could send the storeChecked event, but the first idea didn't work (I've since realized that helper functions like raise and assign actually return an action definition, not cause the "effect"), and the second idea I haven't tried yet since it doesn't quite feel right. Is enqueueActions the right tool for the job in this sort of situation?