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

Function simplifyEvents

packages/core/test/inspect.test.ts:16–69  ·  view source on GitHub ↗
(
  inspectionEvents: InspectionEvent[],
  filter?: (ev: InspectionEvent) => boolean
)

Source from the content-addressed store, hash-verified

14import { InspectedActionEvent } from '../src/inspection';
15
16function simplifyEvents(
17 inspectionEvents: InspectionEvent[],
18 filter?: (ev: InspectionEvent) => boolean
19) {
20 return inspectionEvents
21 .filter(filter ?? (() => true))
22 .map((inspectionEvent) => {
23 if (inspectionEvent.type === '@xstate.event') {
24 return {
25 type: inspectionEvent.type,
26 sourceId: inspectionEvent.sourceRef?.sessionId,
27 targetId: inspectionEvent.actorRef.sessionId,
28 event: inspectionEvent.event
29 };
30 }
31 if (inspectionEvent.type === '@xstate.actor') {
32 return {
33 type: inspectionEvent.type,
34 actorId: inspectionEvent.actorRef.sessionId
35 };
36 }
37
38 if (inspectionEvent.type === '@xstate.snapshot') {
39 return {
40 type: inspectionEvent.type,
41 actorId: inspectionEvent.actorRef.sessionId,
42 snapshot: isMachineSnapshot(inspectionEvent.snapshot)
43 ? { value: inspectionEvent.snapshot.value }
44 : inspectionEvent.snapshot,
45 event: inspectionEvent.event,
46 status: inspectionEvent.snapshot.status
47 };
48 }
49
50 if (inspectionEvent.type === '@xstate.microstep') {
51 return {
52 type: inspectionEvent.type,
53 value: (inspectionEvent.snapshot as any).value,
54 event: inspectionEvent.event,
55 transitions: inspectionEvent._transitions.map((t) => ({
56 eventType: t.eventType,
57 target: t.target?.map((target) => target.id) ?? []
58 }))
59 };
60 }
61
62 if (inspectionEvent.type === '@xstate.action') {
63 return {
64 type: inspectionEvent.type,
65 action: inspectionEvent.action
66 };
67 }
68 });
69}
70
71describe('inspect', () => {
72 it('the .inspect option can observe inspection events', async () => {

Callers 1

inspect.test.tsFile · 0.85

Calls 1

isMachineSnapshotFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…