@internal
(
snapshot: MachineSnapshot<
TContext,
TEvent,
any,
any,
any,
any,
any, // TMeta
any // TStateSchema
>,
event: TEvent
)
| 364 | |
| 365 | /** @internal */ |
| 366 | public next( |
| 367 | snapshot: MachineSnapshot< |
| 368 | TContext, |
| 369 | TEvent, |
| 370 | any, |
| 371 | any, |
| 372 | any, |
| 373 | any, |
| 374 | any, // TMeta |
| 375 | any // TStateSchema |
| 376 | >, |
| 377 | event: TEvent |
| 378 | ): TransitionDefinition<TContext, TEvent>[] | undefined { |
| 379 | const eventType = event.type; |
| 380 | const actions: UnknownAction[] = []; |
| 381 | |
| 382 | let selectedTransition: TransitionDefinition<TContext, TEvent> | undefined; |
| 383 | |
| 384 | const candidates: Array<TransitionDefinition<TContext, TEvent>> = memo( |
| 385 | this, |
| 386 | `candidates-${eventType}`, |
| 387 | () => getCandidates(this, eventType) |
| 388 | ); |
| 389 | |
| 390 | for (const candidate of candidates) { |
| 391 | const { guard } = candidate; |
| 392 | const resolvedContext = snapshot.context; |
| 393 | |
| 394 | let guardPassed = false; |
| 395 | |
| 396 | try { |
| 397 | guardPassed = |
| 398 | !guard || |
| 399 | evaluateGuard<TContext, TEvent>( |
| 400 | guard, |
| 401 | resolvedContext, |
| 402 | event, |
| 403 | snapshot |
| 404 | ); |
| 405 | } catch (err: any) { |
| 406 | const guardType = |
| 407 | typeof guard === 'string' |
| 408 | ? guard |
| 409 | : typeof guard === 'object' |
| 410 | ? guard.type |
| 411 | : undefined; |
| 412 | throw new Error( |
| 413 | `Unable to evaluate guard ${ |
| 414 | guardType ? `'${guardType}' ` : '' |
| 415 | }in transition for event '${eventType}' in state node '${ |
| 416 | this.id |
| 417 | }':\n${err.message}` |
| 418 | ); |
| 419 | } |
| 420 | |
| 421 | if (guardPassed) { |
| 422 | actions.push(...candidate.actions); |
| 423 | selectedTransition = candidate; |
no test coverage detected