Skip to content
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

Hierarchical State Nodes - Executing actions on deep transitions #17

Open
SimonGAndrews opened this issue Sep 19, 2022 · 1 comment
Open

Comments

@SimonGAndrews
Copy link
Owner

In xstate/fsm, identifying the actions to execute on a transition is relatively :) straightforward. The actions returned from a transition (for execution in the interpreter) are:

  • any onexit of the source
  • any actions of the transition
  • any onentry of the target

(all excluding any assign actions effecting the context, which are handled inside the transition by updating the returned context)
see next comment for as is xstate/fsm code for handling transition actions.
"In the presence of compound states, transitions no longer simply move from the current active state to a new active state, but from one set of active states to another." See 3.1.4 and 3.1.5 at https://www.w3.org/TR/scxml/

In particular the scxml spec describes in 3.1.5 that upon a transition, a sequence of onexit and onentry actions (along with defined transition actions) is required for all active states, dependig upon the source and target states.

Hence a function is required in xstate/fsm-plus to implement this logic and return an array of actions that are to be executed on a given transition from a source to target states.

@SimonGAndrews
Copy link
Owner Author

SimonGAndrews commented Sep 19, 2022

for reference - xstate/fsm as is functionality for handling transition actions:
image
Diagram shows asis xstate/fsm code for handling actions on transition (note this is after changes to replace JS destructuring which is not supported in Espruino JS).

1 extracts any transition actions from the transition object
2 build allActions array with actions concat with current state onExit actions plus target state onEntry actions
3 handles any assign actions and returns the modified context and any 'non assign' actions for returning from the transition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant