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

Figure out a better way for matching the current state #56

Open
matthewp opened this issue Sep 24, 2019 · 2 comments · May be fixed by #119
Open

Figure out a better way for matching the current state #56

matthewp opened this issue Sep 24, 2019 · 2 comments · May be fixed by #119
Labels
enhancement New feature or request
Milestone

Comments

@matthewp
Copy link
Owner

In this branch I implemented matches() which works like in XState: https://github.com/matthewp/robot/tree/matches

That is, you can do something like this:

service.matches('foo.bar');

Which will return true of the state is foo and the child machine's state is bar. This is pretty nice.

However, one thing I've wanted for a while is the ability to do unions for matching. In JavaScript you can use bitwise operators to do union matching, like so:

const Red = 1;
const Yellow = 1 << 1;
const Green = 1 << 2;

const CanGo = Yellow | Green;

It would be cool to incorporate this into Robot some how. What if you could pass such a union into a service.matches() API like so:

service.machine.current; // "yellow";

service.matches(Yellow); // true
service.matches(Green); // false
service.matches(CanGo); // true

I'd like to explore possibly allowing for such a thing. This would likely mean creating the state bits so users don't have to. Here's a possibly api:

const { yellow, green } = machine.states;

service.matches(yellow | green);

This seems fine. What about child states though? I would want to incorporate these some how as well so you can do the sort of service.matches('foo.bar') check that's shown at the top of this issue.

@matthewp matthewp added the enhancement New feature or request label Sep 24, 2019
@matthewp
Copy link
Owner Author

Tricky part of the above idea is how you match against child machines. For example:

const child = createMachine({
  one: state(transition('next', 'two')),
  two: state()
});

const machine = createMachine({
  nested: invoke(child, transition('done', 'next')),
  next: state()
});

How can you match nested.one in this case?

@matthewp matthewp mentioned this issue Apr 25, 2020
@matthewp matthewp added this to the Road to 1.0 milestone Apr 25, 2020
@matthewp
Copy link
Owner Author

I think the string way is probably fine for 1.0, and then figure out something better after.

@matthewp matthewp linked a pull request May 14, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant