Matching
Four helpers that answer: where is the machine right now?
matches
Section titled “matches”Dot-notation path check. Prefix match, top-level only.
matches(checkout, "payment"); // top-levelmatches(checkout, "basicInfo"); // top-levelWith fraud region, the path includes region names:
matches(checkoutWithFraud, "basicInfo"); // truematches(checkoutWithFraud, "basicInfo.scanning"); // true (region child)matches(checkoutWithFraud, "basicInfo.cleared"); // falseNot 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" anywhereChecks the full path and all regions.
activeLeaves
Section titled “activeLeaves”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();taggroups at the top level.has()searches the whole tree- Scales: many states, one check