MCPcopy
hub / github.com/statelyai/xstate / next

Method next

packages/core/src/StateNode.ts:366–429  ·  view source on GitHub ↗

@internal

(
    snapshot: MachineSnapshot<
      TContext,
      TEvent,
      any,
      any,
      any,
      any,
      any, // TMeta
      any // TStateSchema
    >,
    event: TEvent
  )

Source from the content-addressed store, hash-verified

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;

Callers 14

notifyInspectionFunction · 0.80
createStoreCoreFunction · 0.80
subscribeFunction · 0.80
updateMethod · 0.80
selectMethod · 0.80
transitionAtomicNodeFunction · 0.80
transitionCompoundNodeFunction · 0.80
transitionParallelNodeFunction · 0.80
sendInspectionEventFunction · 0.80
useActor.test.tsxFile · 0.80
inspectFunction · 0.80

Calls 3

memoFunction · 0.90
getCandidatesFunction · 0.90
evaluateGuardFunction · 0.90

Tested by

no test coverage detected