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

States which act as a second possible initial state should not be marked as unreachable #227

Open
mattpocock opened this issue Mar 24, 2024 · 3 comments

Comments

@mattpocock
Copy link
Contributor

I might want to start my machine in one of two possible initial states. I don't want a warning that this state is unreachable.

Another way to do this might be to be able to dismiss alerts on states.

@Andarist
Copy link
Member

A better pattern would be to allow initial transitions to select the actual initial state. This way the selection logic would be encoded in the machine which would be a good thing from the modeling PoV.

@davidkpiano
Copy link
Member

A better pattern would be to allow initial transitions to select the actual initial state. This way the selection logic would be encoded in the machine which would be a good thing from the modeling PoV.

How would this look? (Pseudocode welcome)

@Andarist
Copy link
Member

createMachine({
  initial: [
    {
      guard: ({ event }) => event.input.isServerEnabled,
      target: "enabled",
    },
    {
      target: "disabled",
    },
  ],
  states: {
    enabled: {
      on: {
        TOGGLE: "disabled",
      },
    },
    disabled: {
      on: {
        TOGGLE: "enabled",
      },
    },
  },
});

IIRC we don't currently support this at runtime but we totally could support it. It's also something that is supported by SCXML and I think it makes a lot of sense to support this. It shouldn't also be a big problem figuring out how to visualize this.

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

3 participants