Function: contextFieldMatches()
API / @xmachines/play-xstate / contextFieldMatches
function contextFieldMatches<TContext>(fieldPath, expectedValue): Guard<TContext, PlayEvent>;Defined in: packages/play-xstate/src/guards/helpers.ts:71
Check if a context field matches an expected value.
- Accepts an explicit dot-separated field path (e.g.
"user.role") - Uses strict equality for primitives, deep structural equality for objects
- Object comparison is key-order-insensitive:
{a:1,b:2}equals{b:2,a:1} - Supports Date, RegExp, class instances, nested objects and arrays via
dequal/lite - Does NOT use substring matching —
"a"will not match"active"
For XState state-node matching, use the built-in in: guard syntax instead.
Type Parameters
| Type Parameter | Default type |
|---|---|
TContext | Record<string, unknown> |
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldPath | string | Dot-separated path to context property (e.g., “status”, “user.role”) |
expectedValue | unknown | Value to compare against (string, object, Date, etc.) |
Returns
Guard predicate checking if context field matches