Skip to content

Should we support internal transitions? #13

Open

Description

@dschnare

See: https://xstate.js.org/docs/guides/transitions.html#internal-transitions

Perhaps we add a new operator to signal the transition should be internal? This is not just an XState only thing, this is also supported by the SCXML spec.

I don't know what the character would be. Maybe hat ^?

@machine App
  Pen
    normal -> ^Normal
    bold -> ^Bold
    fine -> ^Fine
    Normal*
    Bold
    Fine

Only reason I suggest we consider this is this could give the statechart author greater control over component redraws.

Activity

  1. matb33 commented on Jul 26, 2019

    @matb33
    Contributor

    This will be tricky. My understanding is that an internal transition is only available to sibling states. In xstate, you use the dot character to indicate that.

    But we use IDs everywhere, so it won’t be obvious that you can’t target non-siblings.

    This will need some thought before we attempt an implementation.

    Ideally we will have a real world use case first to drive this through.

  2. matb33 commented on Nov 6, 2019

    @matb33
    Contributor

    I ran into a potential use case for this. I needed the state to still change (therefore React to eventually re-render) without leaving and re-entering the state (I didn't want the callback to be called again -- I only wanted the "state" to change).

    E.g.:

    Loading First Thing
      updated caption -> ^Loading First Thing
      success -> Loading Second Thing
    Loading Second Thing
      updated caption -> ^Loading Second Thing
      success -> Done
    Done
    

    and in Loading First Thing.js:

    export async function (evt, send) {
      data.loadingCaption = 'Loading first thing...'
      send('updated caption')
      data.stuff = await loadFirstThing()
      send('success')
    }
    

    and in Loading Second Thing.js:

    export async function (evt, send) {
      data.loadingCaption = 'Loading second thing...'
      send('updated caption')
      data.stuff2 = await loadSecondThing()
      send('success')
    }
    

    Currently I have to split out the caption update stuff into its own state. It's explicit and correct, but lengthy... this is what i have to do now:

    Loading First Thing Caption Update
      updated caption -> Loading First Thing
    Loading First Thing
      success -> Loading Second Thing Caption Update
    Loading Second Thing Caption Update
      updated caption -> Loading Second Thing
    Loading Second Thing
      success -> Done
    Done
    

    and a callback file for each

  3. reopened this on Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

questionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions