Xstate: Root transitions are not working properly

Created on 6 Feb 2019  路  10Comments  路  Source: davidkpiano/xstate

Consider the following snippet:

const wordMachine = Machine({
  id: 'direction',
  initial: 'left',
  states: {
    left: {},
    right: {},
    center: {},
    justify: {}
  },
  on: {
    LEFT_CLICK: 'left',
    RIGHT_CLICK: 'right',
    CENTER_CLICK: 'center',
    JUSTIFY_CLICK: 'justify'
  }
});

If you copy and paste it in the Visualizer (https://statecharts.github.io/xstate-viz/) you'll see that you can transition to right by clicking on RIGHT_CLICK event.

It shouldn't happen. left means "travel to my sibling left state", direction has no siblings.

The expected result would be a warning: Target 'left' not found on 'direction' (or something like that).

bug

Most helpful comment

No problem, thanks for looking into them!

All 10 comments

This is explicitly allowed here so I'm wondering if it's indeed a bug or just a documentation issue?

I think it's a bug. left means a transition to a sibling, not to a child.

If you add a parent foo state, the machine will be interpreted correctly:

const wordMachine = Machine({
  id: 'direction',
  initial: "foo",
  states: {
    foo: {
      initial: 'left',
      states: {
        left: {},
        right: {},
        center: {},
        justify: {}
      },
      on: {
        LEFT_CLICK: 'left',
        RIGHT_CLICK: 'right',
        CENTER_CLICK: 'center',
        JUSTIFY_CLICK: 'justify'
      }
    }
  }
});

It won't allow you to transition from left to right on RIGHT_CLICK because there's no right sibling.

Yes, I believe they are wrong.

Waiting @davidkpiano thoughts on it.

For me transitions without a dot always mean a transition to a sibling state, and it should not resolve to a child state in any case.

If sibling transitions behave some way for the root state and then another way for children states, it's gonna be confusing.

Yeah, they're wrong. Will fix.

Guys, does this issue still stand or perhaps it could be closed after the https://github.com/davidkpiano/xstate/pull/550 ?

@abhi18av the issue still stands. It indeed got fixed in #550 but we couldn't merge it in, because it is a breaking change and we need to wait for the next major version for this to be fixed.

Cool 馃憤

I'm trying to understand the standing issues and PRs - apologies for notifications 馃槄

No problem, thanks for looking into them!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kurtmilam picture kurtmilam  路  3Comments

doup picture doup  路  3Comments

drmikecrowe picture drmikecrowe  路  3Comments

ifokeev picture ifokeev  路  3Comments

bradwoods picture bradwoods  路  3Comments