Function: contextFieldMatches()
API / @xmachines/play-xstate / contextFieldMatches
function contextFieldMatches<TContext>(fieldPath, expectedValue): Guard<TContext, PlayEvent>;Defined in: packages/play-xstate/src/guards/helpers.ts:75
Tells you if a context field holds the expected value.
- The function accepts an explicit field path, with a dot between two segments, for example
"user.role" - It compares a primitive with a strict equality, and an object with a deep structural equality
- The order of the keys has no effect on the comparison of an object:
{a:1,b:2}equals{b:2,a:1} - It supports a Date, a RegExp, an instance of a class, a nested object, and an array, through
dequal/lite - It does NOT match a substring:
"a"does not match"active"
For a match of an XState state node, use the built-in in: guard syntax instead.
Type Parameters
| Type Parameter | Default type |
|---|---|
TContext | Record<string, unknown> |
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldPath | string | The path to the context property, with a dot between two segments, for example “status” or “user.role” |
expectedValue | unknown | The value for the comparison: a string, an object, a Date, and so on |
Returns
The guard predicate. It tests the context field for the value
Deprecated
This function is part of the guard utilities, and the next major version removes them. Write a plain typed predicate instead.