Skip to content

Commit

Permalink
fixup! refactor: Store startPoint, waypoints, and endPoint as separat…
Browse files Browse the repository at this point in the history
…e pieces of context
  • Loading branch information
joshlarson committed May 28, 2024
1 parent ffb00cd commit 5917f45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions assets/src/hooks/useDetour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const useDetour = ({ routePatternId, shape }: OriginalRoute) => {
/** The detour waypoints in-between the start and end point */
const waypoints = snapshot.context.waypoints
const allPoints = useMemo(() => {
if (startPoint === null) {
if (!startPoint) {
return []
} else if (endPoint === null) {
} else if (!endPoint) {
return [startPoint].concat(waypoints)
} else {
return [startPoint].concat(waypoints).concat([endPoint])
Expand Down
16 changes: 8 additions & 8 deletions assets/src/models/createDetourMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ShapePoint } from "../schedule"
export const createDetourMachine = setup({
types: {} as {
context: {
startPoint: ShapePoint | null
endPoint: ShapePoint | null
startPoint: ShapePoint | undefined
endPoint: ShapePoint | undefined
waypoints: ShapePoint[]
}
events:
Expand All @@ -22,7 +22,7 @@ export const createDetourMachine = setup({
startPoint: (_, params: { location: ShapePoint }) => params.location,
}),
"detour.remove-start-point": assign({
startPoint: null,
startPoint: undefined,
}),
"detour.add-waypoint": assign({
waypoints: ({ context }, params: { location: ShapePoint }) => [
Expand All @@ -37,11 +37,11 @@ export const createDetourMachine = setup({
endPoint: (_, params: { location: ShapePoint }) => params.location,
}),
"detour.remove-end-point": assign({
endPoint: null,
endPoint: undefined,
}),
"detour.clear": assign({
startPoint: null,
endPoint: null,
startPoint: undefined,
endPoint: undefined,
waypoints: [],
}),

Expand All @@ -53,8 +53,8 @@ export const createDetourMachine = setup({
id: "Detours Machine",
context: () => ({
waypoints: [],
startPoint: null,
endPoint: null,
startPoint: undefined,
endPoint: undefined,
}),

initial: "Detour Drawing",
Expand Down

0 comments on commit 5917f45

Please sign in to comment.