xstate 5.6.2 → 5.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/State.d.ts +5 -5
  14. package/dist/declarations/src/index.d.ts +3 -2
  15. package/dist/declarations/src/inspection.d.ts +38 -0
  16. package/dist/declarations/src/system.d.ts +2 -25
  17. package/dist/declarations/src/types.d.ts +2 -1
  18. package/dist/{log-75c83841.development.cjs.js → log-9b34dd45.development.cjs.js} +1 -1
  19. package/dist/{log-c5c46d15.cjs.js → log-c2d7ade7.cjs.js} +1 -1
  20. package/dist/{log-edca19d9.development.esm.js → log-dc9ca1e2.development.esm.js} +1 -1
  21. package/dist/{log-b6ecfc82.esm.js → log-f78f0918.esm.js} +1 -1
  22. package/dist/{raise-d7d9caaa.development.cjs.js → raise-0ce4ccae.development.cjs.js} +55 -26
  23. package/dist/{raise-2fdbadc6.development.esm.js → raise-4593d184.development.esm.js} +55 -26
  24. package/dist/{raise-309d511a.esm.js → raise-6420fe44.esm.js} +55 -26
  25. package/dist/{raise-540fdaf2.cjs.js → raise-932934e8.cjs.js} +55 -26
  26. package/dist/xstate.cjs.js +2 -2
  27. package/dist/xstate.development.cjs.js +2 -2
  28. package/dist/xstate.development.esm.js +4 -4
  29. package/dist/xstate.esm.js +4 -4
  30. package/dist/xstate.umd.min.js +1 -1
  31. package/dist/xstate.umd.min.js.map +1 -1
  32. package/guards/dist/xstate-guards.cjs.js +1 -1
  33. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  34. package/guards/dist/xstate-guards.development.esm.js +1 -1
  35. package/guards/dist/xstate-guards.esm.js +1 -1
  36. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,38 @@
1
+ import { AnyActorRef, AnyEventObject, AnyTransitionDefinition, Snapshot } from "./types.js";
2
+ export type InspectionEvent = InspectedSnapshotEvent | InspectedEventEvent | InspectedActorEvent | InspectedMicrostepEvent | InspectedActionEvent;
3
+ export interface BaseInspectionEventProperties {
4
+ rootId: string;
5
+ /**
6
+ * The relevant actorRef for the inspection event.
7
+ * - For snapshot events, this is the `actorRef` of the snapshot.
8
+ * - For event events, this is the target `actorRef` (recipient of event).
9
+ * - For actor events, this is the `actorRef` of the registered actor.
10
+ */
11
+ actorRef: AnyActorRef;
12
+ }
13
+ export interface InspectedSnapshotEvent extends BaseInspectionEventProperties {
14
+ type: '@xstate.snapshot';
15
+ event: AnyEventObject;
16
+ snapshot: Snapshot<unknown>;
17
+ }
18
+ export interface InspectedMicrostepEvent extends BaseInspectionEventProperties {
19
+ type: '@xstate.microstep';
20
+ event: AnyEventObject;
21
+ snapshot: Snapshot<unknown>;
22
+ _transitions: AnyTransitionDefinition[];
23
+ }
24
+ export interface InspectedActionEvent extends BaseInspectionEventProperties {
25
+ type: '@xstate.action';
26
+ action: {
27
+ type: string;
28
+ params: Record<string, unknown>;
29
+ };
30
+ }
31
+ export interface InspectedEventEvent extends BaseInspectionEventProperties {
32
+ type: '@xstate.event';
33
+ sourceRef: AnyActorRef | undefined;
34
+ event: AnyEventObject;
35
+ }
36
+ export interface InspectedActorEvent extends BaseInspectionEventProperties {
37
+ type: '@xstate.actor';
38
+ }
@@ -1,4 +1,5 @@
1
- import { AnyEventObject, ActorSystemInfo, AnyActorRef, Observer, Snapshot, EventObject } from "./types.js";
1
+ import { InspectionEvent } from "./inspection.js";
2
+ import { ActorSystemInfo, AnyActorRef, Observer, EventObject } from "./types.js";
2
3
  export interface ScheduledEvent {
3
4
  id: string;
4
5
  event: EventObject;
@@ -30,27 +31,3 @@ export declare function createSystem<T extends ActorSystemInfo>(rootActor: AnyAc
30
31
  clock: Clock;
31
32
  snapshot?: unknown;
32
33
  }): ActorSystem<T>;
33
- export interface BaseInspectionEventProperties {
34
- rootId: string;
35
- /**
36
- * The relevant actorRef for the inspection event.
37
- * - For snapshot events, this is the `actorRef` of the snapshot.
38
- * - For event events, this is the target `actorRef` (recipient of event).
39
- * - For actor events, this is the `actorRef` of the registered actor.
40
- */
41
- actorRef: AnyActorRef;
42
- }
43
- export interface InspectedSnapshotEvent extends BaseInspectionEventProperties {
44
- type: '@xstate.snapshot';
45
- event: AnyEventObject;
46
- snapshot: Snapshot<unknown>;
47
- }
48
- export interface InspectedEventEvent extends BaseInspectionEventProperties {
49
- type: '@xstate.event';
50
- sourceRef: AnyActorRef | undefined;
51
- event: AnyEventObject;
52
- }
53
- export interface InspectedActorEvent extends BaseInspectionEventProperties {
54
- type: '@xstate.actor';
55
- }
56
- export type InspectionEvent = InspectedSnapshotEvent | InspectedEventEvent | InspectedActorEvent;
@@ -6,7 +6,8 @@ import { PromiseActorLogic } from "./actors/promise.js";
6
6
  import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
7
7
  import type { Actor } from "./createActor.js";
8
8
  import { Spawner } from "./spawn.js";
9
- import { AnyActorSystem, InspectionEvent, Clock } from './system.js';
9
+ import { AnyActorSystem, Clock } from './system.js';
10
+ import { InspectionEvent } from "./inspection.js";
10
11
  import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
11
12
  export type Identity<T> = {
12
13
  [K in keyof T]: T[K];
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-d7d9caaa.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-0ce4ccae.development.cjs.js');
4
4
 
5
5
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
6
6
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-540fdaf2.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-932934e8.cjs.js');
4
4
 
5
5
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
6
6
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -1,4 +1,4 @@
1
- import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-2fdbadc6.development.esm.js';
1
+ import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-4593d184.development.esm.js';
2
2
 
3
3
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
4
4
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -1,4 +1,4 @@
1
- import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-309d511a.esm.js';
1
+ import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-6420fe44.esm.js';
2
2
 
3
3
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
4
4
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -136,7 +136,7 @@ function createSystem(rootActor, options) {
136
136
  const children = new Map();
137
137
  const keyedActors = new Map();
138
138
  const reverseKeyedActors = new WeakMap();
139
- const observers = new Set();
139
+ const inspectionObservers = new Set();
140
140
  const timerMap = {};
141
141
  const clock = options.clock;
142
142
  const scheduler = {
@@ -174,6 +174,16 @@ function createSystem(rootActor, options) {
174
174
  }
175
175
  }
176
176
  };
177
+ const sendInspectionEvent = event => {
178
+ if (!inspectionObservers.size) {
179
+ return;
180
+ }
181
+ const resolvedInspectionEvent = {
182
+ ...event,
183
+ rootId: rootActor.sessionId
184
+ };
185
+ inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
186
+ };
177
187
  const system = {
178
188
  _snapshot: {
179
189
  _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
@@ -203,15 +213,9 @@ function createSystem(rootActor, options) {
203
213
  reverseKeyedActors.set(actorRef, systemId);
204
214
  },
205
215
  inspect: observer => {
206
- observers.add(observer);
207
- },
208
- _sendInspectionEvent: event => {
209
- const resolvedInspectionEvent = {
210
- ...event,
211
- rootId: rootActor.sessionId
212
- };
213
- observers.forEach(observer => observer.next?.(resolvedInspectionEvent));
216
+ inspectionObservers.add(observer);
214
217
  },
218
+ _sendInspectionEvent: sendInspectionEvent,
215
219
  _relay: (source, target, event) => {
216
220
  system._sendInspectionEvent({
217
221
  type: '@xstate.event',
@@ -230,16 +234,16 @@ function createSystem(rootActor, options) {
230
234
  };
231
235
  },
232
236
  start: () => {
233
- const scheduledEvets = system._snapshot._scheduledEvents;
237
+ const scheduledEvents = system._snapshot._scheduledEvents;
234
238
  system._snapshot._scheduledEvents = {};
235
- for (const scheduledId in scheduledEvets) {
239
+ for (const scheduledId in scheduledEvents) {
236
240
  const {
237
241
  source,
238
242
  target,
239
243
  event,
240
244
  delay,
241
245
  id
242
- } = scheduledEvets[scheduledId];
246
+ } = scheduledEvents[scheduledId];
243
247
  scheduler.schedule(source, target, event, delay, id);
244
248
  }
245
249
  }
@@ -1790,7 +1794,11 @@ function getStateNodeByPath(stateNode, statePath) {
1790
1794
  */
1791
1795
  function getStateNodes(stateNode, stateValue) {
1792
1796
  if (typeof stateValue === 'string') {
1793
- return [stateNode, stateNode.states[stateValue]];
1797
+ const childStateNode = stateNode.states[stateValue];
1798
+ if (!childStateNode) {
1799
+ throw new Error(`State '${stateValue}' does not exist on '${stateNode.id}'`);
1800
+ }
1801
+ return [stateNode, childStateNode];
1794
1802
  }
1795
1803
  const childStateKeys = Object.keys(stateValue);
1796
1804
  const childStateNodes = childStateKeys.map(subStateKey => getStateNode(stateNode, subStateKey)).filter(Boolean);
@@ -2203,7 +2211,7 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
2203
2211
  }
2204
2212
  return [nextSnapshot, changedHistory || historyValue];
2205
2213
  }
2206
- function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, extra, retries) {
2214
+ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
2207
2215
  const {
2208
2216
  machine
2209
2217
  } = currentSnapshot;
@@ -2228,12 +2236,23 @@ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, acti
2228
2236
  context: intermediateSnapshot.context,
2229
2237
  event
2230
2238
  }) : action.params : undefined;
2239
+ function executeAction() {
2240
+ actorScope.system._sendInspectionEvent({
2241
+ type: '@xstate.action',
2242
+ actorRef: actorScope.self,
2243
+ action: {
2244
+ type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
2245
+ params: actionParams
2246
+ }
2247
+ });
2248
+ resolvedAction(actionArgs, actionParams);
2249
+ }
2231
2250
  if (!('resolve' in resolvedAction)) {
2232
2251
  if (actorScope.self._processingStatus === ProcessingStatus.Running) {
2233
- resolvedAction(actionArgs, actionParams);
2252
+ executeAction();
2234
2253
  } else {
2235
2254
  actorScope.defer(() => {
2236
- resolvedAction(actionArgs, actionParams);
2255
+ executeAction();
2237
2256
  });
2238
2257
  }
2239
2258
  continue;
@@ -2254,14 +2273,14 @@ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, acti
2254
2273
  }
2255
2274
  }
2256
2275
  if (actions) {
2257
- intermediateSnapshot = resolveActionsAndContextWorker(intermediateSnapshot, event, actorScope, actions, extra, retries);
2276
+ intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
2258
2277
  }
2259
2278
  }
2260
2279
  return intermediateSnapshot;
2261
2280
  }
2262
2281
  function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
2263
2282
  const retries = deferredActorIds ? [] : undefined;
2264
- const nextState = resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, {
2283
+ const nextState = resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, {
2265
2284
  internalQueue,
2266
2285
  deferredActorIds
2267
2286
  }, retries);
@@ -2275,17 +2294,27 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2275
2294
  throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
2276
2295
  }
2277
2296
  let nextSnapshot = snapshot;
2278
- const states = [];
2297
+ const microstates = [];
2298
+ function addMicrostate(microstate, event, transitions) {
2299
+ actorScope.system._sendInspectionEvent({
2300
+ type: '@xstate.microstep',
2301
+ actorRef: actorScope.self,
2302
+ event,
2303
+ snapshot: microstate,
2304
+ _transitions: transitions
2305
+ });
2306
+ microstates.push(microstate);
2307
+ }
2279
2308
 
2280
2309
  // Handle stop event
2281
2310
  if (event.type === XSTATE_STOP) {
2282
2311
  nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
2283
2312
  status: 'stopped'
2284
2313
  });
2285
- states.push(nextSnapshot);
2314
+ addMicrostate(nextSnapshot, event, []);
2286
2315
  return {
2287
2316
  snapshot: nextSnapshot,
2288
- microstates: states
2317
+ microstates
2289
2318
  };
2290
2319
  }
2291
2320
  let nextEvent = event;
@@ -2304,16 +2333,16 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2304
2333
  status: 'error',
2305
2334
  error: currentEvent.error
2306
2335
  });
2307
- states.push(nextSnapshot);
2336
+ addMicrostate(nextSnapshot, currentEvent, []);
2308
2337
  return {
2309
2338
  snapshot: nextSnapshot,
2310
- microstates: states
2339
+ microstates
2311
2340
  };
2312
2341
  }
2313
2342
  nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false,
2314
2343
  // isInitial
2315
2344
  internalQueue);
2316
- states.push(nextSnapshot);
2345
+ addMicrostate(nextSnapshot, currentEvent, transitions);
2317
2346
  }
2318
2347
  let shouldSelectEventlessTransitions = true;
2319
2348
  while (nextSnapshot.status === 'active') {
@@ -2331,14 +2360,14 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2331
2360
  }
2332
2361
  nextSnapshot = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
2333
2362
  shouldSelectEventlessTransitions = nextSnapshot !== previousState;
2334
- states.push(nextSnapshot);
2363
+ addMicrostate(nextSnapshot, nextEvent, enabledTransitions);
2335
2364
  }
2336
2365
  if (nextSnapshot.status !== 'active') {
2337
2366
  stopChildren(nextSnapshot, nextEvent, actorScope);
2338
2367
  }
2339
2368
  return {
2340
2369
  snapshot: nextSnapshot,
2341
- microstates: states
2370
+ microstates
2342
2371
  };
2343
2372
  }
2344
2373
  function stopChildren(nextState, event, actorScope) {
@@ -134,7 +134,7 @@ function createSystem(rootActor, options) {
134
134
  const children = new Map();
135
135
  const keyedActors = new Map();
136
136
  const reverseKeyedActors = new WeakMap();
137
- const observers = new Set();
137
+ const inspectionObservers = new Set();
138
138
  const timerMap = {};
139
139
  const clock = options.clock;
140
140
  const scheduler = {
@@ -172,6 +172,16 @@ function createSystem(rootActor, options) {
172
172
  }
173
173
  }
174
174
  };
175
+ const sendInspectionEvent = event => {
176
+ if (!inspectionObservers.size) {
177
+ return;
178
+ }
179
+ const resolvedInspectionEvent = {
180
+ ...event,
181
+ rootId: rootActor.sessionId
182
+ };
183
+ inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
184
+ };
175
185
  const system = {
176
186
  _snapshot: {
177
187
  _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
@@ -201,15 +211,9 @@ function createSystem(rootActor, options) {
201
211
  reverseKeyedActors.set(actorRef, systemId);
202
212
  },
203
213
  inspect: observer => {
204
- observers.add(observer);
205
- },
206
- _sendInspectionEvent: event => {
207
- const resolvedInspectionEvent = {
208
- ...event,
209
- rootId: rootActor.sessionId
210
- };
211
- observers.forEach(observer => observer.next?.(resolvedInspectionEvent));
214
+ inspectionObservers.add(observer);
212
215
  },
216
+ _sendInspectionEvent: sendInspectionEvent,
213
217
  _relay: (source, target, event) => {
214
218
  system._sendInspectionEvent({
215
219
  type: '@xstate.event',
@@ -228,16 +232,16 @@ function createSystem(rootActor, options) {
228
232
  };
229
233
  },
230
234
  start: () => {
231
- const scheduledEvets = system._snapshot._scheduledEvents;
235
+ const scheduledEvents = system._snapshot._scheduledEvents;
232
236
  system._snapshot._scheduledEvents = {};
233
- for (const scheduledId in scheduledEvets) {
237
+ for (const scheduledId in scheduledEvents) {
234
238
  const {
235
239
  source,
236
240
  target,
237
241
  event,
238
242
  delay,
239
243
  id
240
- } = scheduledEvets[scheduledId];
244
+ } = scheduledEvents[scheduledId];
241
245
  scheduler.schedule(source, target, event, delay, id);
242
246
  }
243
247
  }
@@ -1788,7 +1792,11 @@ function getStateNodeByPath(stateNode, statePath) {
1788
1792
  */
1789
1793
  function getStateNodes(stateNode, stateValue) {
1790
1794
  if (typeof stateValue === 'string') {
1791
- return [stateNode, stateNode.states[stateValue]];
1795
+ const childStateNode = stateNode.states[stateValue];
1796
+ if (!childStateNode) {
1797
+ throw new Error(`State '${stateValue}' does not exist on '${stateNode.id}'`);
1798
+ }
1799
+ return [stateNode, childStateNode];
1792
1800
  }
1793
1801
  const childStateKeys = Object.keys(stateValue);
1794
1802
  const childStateNodes = childStateKeys.map(subStateKey => getStateNode(stateNode, subStateKey)).filter(Boolean);
@@ -2201,7 +2209,7 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
2201
2209
  }
2202
2210
  return [nextSnapshot, changedHistory || historyValue];
2203
2211
  }
2204
- function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, extra, retries) {
2212
+ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
2205
2213
  const {
2206
2214
  machine
2207
2215
  } = currentSnapshot;
@@ -2226,12 +2234,23 @@ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, acti
2226
2234
  context: intermediateSnapshot.context,
2227
2235
  event
2228
2236
  }) : action.params : undefined;
2237
+ function executeAction() {
2238
+ actorScope.system._sendInspectionEvent({
2239
+ type: '@xstate.action',
2240
+ actorRef: actorScope.self,
2241
+ action: {
2242
+ type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
2243
+ params: actionParams
2244
+ }
2245
+ });
2246
+ resolvedAction(actionArgs, actionParams);
2247
+ }
2229
2248
  if (!('resolve' in resolvedAction)) {
2230
2249
  if (actorScope.self._processingStatus === ProcessingStatus.Running) {
2231
- resolvedAction(actionArgs, actionParams);
2250
+ executeAction();
2232
2251
  } else {
2233
2252
  actorScope.defer(() => {
2234
- resolvedAction(actionArgs, actionParams);
2253
+ executeAction();
2235
2254
  });
2236
2255
  }
2237
2256
  continue;
@@ -2252,14 +2271,14 @@ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, acti
2252
2271
  }
2253
2272
  }
2254
2273
  if (actions) {
2255
- intermediateSnapshot = resolveActionsAndContextWorker(intermediateSnapshot, event, actorScope, actions, extra, retries);
2274
+ intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
2256
2275
  }
2257
2276
  }
2258
2277
  return intermediateSnapshot;
2259
2278
  }
2260
2279
  function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
2261
2280
  const retries = deferredActorIds ? [] : undefined;
2262
- const nextState = resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, {
2281
+ const nextState = resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, {
2263
2282
  internalQueue,
2264
2283
  deferredActorIds
2265
2284
  }, retries);
@@ -2273,17 +2292,27 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2273
2292
  throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
2274
2293
  }
2275
2294
  let nextSnapshot = snapshot;
2276
- const states = [];
2295
+ const microstates = [];
2296
+ function addMicrostate(microstate, event, transitions) {
2297
+ actorScope.system._sendInspectionEvent({
2298
+ type: '@xstate.microstep',
2299
+ actorRef: actorScope.self,
2300
+ event,
2301
+ snapshot: microstate,
2302
+ _transitions: transitions
2303
+ });
2304
+ microstates.push(microstate);
2305
+ }
2277
2306
 
2278
2307
  // Handle stop event
2279
2308
  if (event.type === XSTATE_STOP) {
2280
2309
  nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
2281
2310
  status: 'stopped'
2282
2311
  });
2283
- states.push(nextSnapshot);
2312
+ addMicrostate(nextSnapshot, event, []);
2284
2313
  return {
2285
2314
  snapshot: nextSnapshot,
2286
- microstates: states
2315
+ microstates
2287
2316
  };
2288
2317
  }
2289
2318
  let nextEvent = event;
@@ -2302,16 +2331,16 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2302
2331
  status: 'error',
2303
2332
  error: currentEvent.error
2304
2333
  });
2305
- states.push(nextSnapshot);
2334
+ addMicrostate(nextSnapshot, currentEvent, []);
2306
2335
  return {
2307
2336
  snapshot: nextSnapshot,
2308
- microstates: states
2337
+ microstates
2309
2338
  };
2310
2339
  }
2311
2340
  nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false,
2312
2341
  // isInitial
2313
2342
  internalQueue);
2314
- states.push(nextSnapshot);
2343
+ addMicrostate(nextSnapshot, currentEvent, transitions);
2315
2344
  }
2316
2345
  let shouldSelectEventlessTransitions = true;
2317
2346
  while (nextSnapshot.status === 'active') {
@@ -2329,14 +2358,14 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2329
2358
  }
2330
2359
  nextSnapshot = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
2331
2360
  shouldSelectEventlessTransitions = nextSnapshot !== previousState;
2332
- states.push(nextSnapshot);
2361
+ addMicrostate(nextSnapshot, nextEvent, enabledTransitions);
2333
2362
  }
2334
2363
  if (nextSnapshot.status !== 'active') {
2335
2364
  stopChildren(nextSnapshot, nextEvent, actorScope);
2336
2365
  }
2337
2366
  return {
2338
2367
  snapshot: nextSnapshot,
2339
- microstates: states
2368
+ microstates
2340
2369
  };
2341
2370
  }
2342
2371
  function stopChildren(nextState, event, actorScope) {