Function: composeGuardsOr()
Documentation / @xmachines/play-xstate / composeGuardsOr
function composeGuardsOr<TContext, TEvent>(guards): ComposedGuard;Defined in: packages/play-xstate/src/guards/compose.ts:143
Compose guards with OR logic using XState’s or() helper
Combines multiple guard predicates using OR semantics—at least one guard must pass
for the composition to succeed. Uses XState’s built-in or() helper for proper
type inference.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TContext | any | State machine context type |
TEvent | any | Event type |
Parameters
| Parameter | Type | Description |
|---|---|---|
guards | GuardArray<TContext, TEvent> | Array of guard predicates or guard names |
Returns
XState or() guard composition
Throws
If guards array is empty
Example
OR composition with named guards
import { setup } from "xstate";import { composeGuardsOr } from "@xmachines/play-xstate";
const machine = setup({ guards: { isOwner: ({ context }) => context.role === "owner", isAdmin: ({ context }) => context.role === "admin", },}).createMachine({ on: { deleteResource: { // Either guard can pass guard: composeGuardsOr(["isOwner", "isAdmin"]), actions: "delete", }, },});See
- composeGuards for AND composition
- negateGuard for NOT logic