Skip to content

Matching

Four helpers that answer: where is the machine right now?

Dot-notation path check. Prefix match, top-level only.

matches(checkout, "payment"); // top-level
matches(checkout, "basicInfo"); // top-level

With fraud region, the path includes region names:

matches(checkoutWithFraud, "basicInfo"); // true
matches(checkoutWithFraud, "basicInfo.scanning"); // true (region child)
matches(checkoutWithFraud, "basicInfo.cleared"); // false

Not a whole-tree search. A nested "payment" under a different top state fails. Use isIn for recursive search.

Without sugar: checkout.snapshot().path[0] === "payment".

Recursive search. Is a state anywhere in the snapshot tree?

isIn(checkoutWithFraud.snapshot(), "cleared"); // true if "cleared" anywhere

Checks the full path and all regions.

All leaf states in the current path.

activeLeaves(checkout.snapshot()); // ["payment"]
activeLeaves(checkoutWithFraud.snapshot()); // ["basicInfo.scanning"]

Returns multiple leaves with parallel regions.

Group states. Check membership.

const busy = tag(submitting, payment);
busy.has(checkout.snapshot()); // true if in submitting or payment
const failed = tag(error, flagged);
if (failed.has(checkout.snapshot())) showRetryUI();
  • tag groups at the top level
  • .has() searches the whole tree
  • Scales: many states, one check