-
Notifications
You must be signed in to change notification settings - Fork 92
Description
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.