Skip to content

Commit 6b52206

Browse files
authored
Clean up machines (#1372)
* Update XState to v5.17.0 * Update all dependencies * Reduce whitespace * Reduce whitespace * Clean up events from appMachine * Reduce whitespace * Increment patch version
1 parent c9228ce commit 6b52206

File tree

5 files changed

+1123
-1929
lines changed

5 files changed

+1123
-1929
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"lucide-react": "^0.471.1",
1616
"next": "15.1.4",
1717
"prettier": "^3.4.2",
18-
"react": "19.0.0",
1918
"react-dom": "19.0.0",
2019
"react-is": "19.0.0",
20+
"react": "19.0.0",
2121
"styled-components": "6.1.14",
2222
"url-loader": "^4.1.1",
2323
"use-sound": "^4.0.3",
@@ -28,16 +28,16 @@
2828
"@types/aria-query": "5.0.4",
2929
"@types/jest": "29.5.14",
3030
"@types/node": "^22.10.7",
31-
"@types/react": "19.0.4",
3231
"@types/react-dom": "19.0.2",
32+
"@types/react": "19.0.4",
3333
"@types/styled-components": "5.1.34",
3434
"@typescript-eslint/eslint-plugin": "8.19.1",
3535
"@typescript-eslint/parser": "8.19.1",
3636
"@typescript-eslint/typescript-estree": "8.19.1",
37-
"eslint": "9.18.0",
3837
"eslint-config-next": "15.1.4",
39-
"prettier": "^3.4.2",
38+
"eslint": "9.18.0",
4039
"prettier-plugin-organize-imports": "^4.1.0",
40+
"prettier": "^3.4.2",
4141
"typescript": "5.7.3"
4242
}
4343
}

src/components/Controls/Controls.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React, { useState } from 'react';
22

33
import { useSelector } from '@xstate/react';
4+
import { EventFrom } from 'xstate';
45
import Pause from '../../assets/svg/controls/pause.svg';
56
import Play from '../../assets/svg/controls/play.svg';
67
import StartOver from '../../assets/svg/controls/start-over.svg';
78
import StepForward from '../../assets/svg/controls/step-forward.svg';
89
import Stop from '../../assets/svg/controls/stop.svg';
910
import {
11+
appMachine,
1012
AppMachineContext,
11-
AppMachineEvent,
1213
ControlEvent,
1314
} from '../../statechart/app.machine';
1415
import { Keyboard } from '../Keyboard/Keyboard';
@@ -116,7 +117,7 @@ export function Controls() {
116117
if (event.detail === 0) {
117118
return;
118119
}
119-
const eventObj = { type: id } as AppMachineEvent;
120+
const eventObj = { type: id } as EventFrom<typeof appMachine>;
120121
actorRef.send(eventObj);
121122
}
122123

src/statechart/app.machine.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createActorContext } from '@xstate/react';
2-
import { EventFrom, StateFrom, assign, sendTo, setup } from 'xstate';
2+
import { assign, sendTo, setup } from 'xstate';
33
import { IGrid } from '../components/generation/Grid';
44
import { GenerationParams } from '../types';
55
import { recursiveBacktrackerMachine } from './recursiveBacktracker.machine';
@@ -71,12 +71,7 @@ export const appMachine =
7171
}),
7272
on: {
7373
'grid.inject': {
74-
actions: [
75-
assign({
76-
grid: ({ event }) => event.grid,
77-
}),
78-
'drawGrid',
79-
],
74+
actions: [assign({ grid: ({ event }) => event.grid }), 'drawGrid'],
8075
target: 'Generating',
8176
},
8277
},
@@ -159,6 +154,3 @@ export const appMachine =
159154
});
160155

161156
export const AppMachineContext = createActorContext(appMachine);
162-
163-
export type AppMachineState = StateFrom<typeof appMachine>;
164-
export type AppMachineEvent = EventFrom<typeof appMachine>;

src/statechart/recursiveBacktracker.machine.ts

+7-22
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@ export const recursiveBacktrackerMachine =
2424
pathId: string;
2525
};
2626
events:
27-
| {
28-
type: 'generation.start';
29-
}
30-
| {
31-
type: 'controls.play';
32-
}
33-
| {
34-
type: 'controls.pause';
35-
}
36-
| {
37-
type: 'controls.step.forward';
38-
};
27+
| { type: 'generation.start' }
28+
| { type: 'controls.play' }
29+
| { type: 'controls.pause' }
30+
| { type: 'controls.step.forward' };
3931
},
4032
guards: {
4133
'can play': ({ context }) => context.canPlay,
@@ -105,9 +97,7 @@ export const recursiveBacktrackerMachine =
10597
},
10698
Seeking: {
10799
entry: ['findNeighbors', 'drawGrid'],
108-
always: {
109-
target: 'Advancing',
110-
},
100+
always: 'Advancing',
111101
},
112102
Advancing: {
113103
entry: ['pickNextCell', 'pushToStack'],
@@ -130,13 +120,8 @@ export const recursiveBacktrackerMachine =
130120
return { stack: [...stack], currentCell: prevCell };
131121
}),
132122
always: [
133-
{
134-
guard: 'back at the start',
135-
target: 'Finished',
136-
},
137-
{
138-
target: 'Seeking',
139-
},
123+
{ guard: 'back at the start', target: 'Finished' },
124+
{ target: 'Seeking' },
140125
],
141126
},
142127
Finished: {

0 commit comments

Comments
 (0)