Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Reset simulation state on receiving xstate.disconnect #291

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slow-pants-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate-viz-app': minor
---

Reset the machine visualization when the inspector source gets disconnected
8 changes: 8 additions & 0 deletions src/simulationMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export const simulationMachine = simModel.createMachine(
}),
);
break;
case 'xstate.disconnect' as any:
sendBack(simModel.events['MACHINES.RESET']());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typecasting will be removed once statelyai/xstate#2720 is merged that adds the typings.

break;
case 'service.state':
sendBack(
simModel.events['SERVICE.STATE'](
Expand All @@ -155,6 +158,11 @@ export const simulationMachine = simModel.createMachine(
}).unsubscribe;
},
},
on: {
'MACHINES.RESET': {
actions: ['resetVisualizationState'],
},
},
},
visualizing: {
tags: 'visualizing',
Expand Down