From 59335be063402736a007383b31f65010ca89cafb Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Fri, 3 Oct 2025 13:46:47 +1000 Subject: [PATCH 1/4] remove spawned child ref --- src/machines/sketchSolve/sketchSolveMode.ts | 35 +++++++-------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/machines/sketchSolve/sketchSolveMode.ts b/src/machines/sketchSolve/sketchSolveMode.ts index ab1dad6314f..40b980a10bc 100644 --- a/src/machines/sketchSolve/sketchSolveMode.ts +++ b/src/machines/sketchSolve/sketchSolveMode.ts @@ -22,6 +22,9 @@ const equipTools = Object.freeze({ pointTool, }) +const CHILD_TOOL = 'child tool' +const CHILD_TOOL_DONE_EVENT = `xstate.done.actor.${CHILD_TOOL}` + export type EquipTool = keyof typeof equipTools // Type for the spawn function used in XState setup actions @@ -37,15 +40,9 @@ export type SketchSolveMachineEvent = | { type: 'update selection'; data?: SetSelections } | { type: 'unequip tool' } | { type: 'equip tool'; data: { tool: EquipTool } } - | { type: 'xstate.done.actor.tool' } - -type ToolActorRef = - | ActorRefFrom - | ActorRefFrom - | ActorRefFrom + | { type: typeof CHILD_TOOL_DONE_EVENT } type SketchSolveContext = ModelingMachineContext & { - toolActor?: ToolActorRef sketchSolveToolName: EquipTool | null pendingToolName?: EquipTool } @@ -56,18 +53,10 @@ export const sketchSolveMachine = setup({ events: {} as SketchSolveMachineEvent, }, actions: { - 'send unequip to tool': sendTo( - ({ context }) => context.toolActor || 'moveTool', - { - type: 'unequip', - } - ), - 'send update selection to equipped tool': sendTo( - ({ context }) => context.toolActor || 'moveTool', - { - type: 'update selection', - } - ), + 'send unequip to tool': sendTo(CHILD_TOOL, { type: 'unequip' }), + 'send update selection to equipped tool': sendTo(CHILD_TOOL, { + type: 'update selection', + }), 'send updated selection to move tool': sendTo('moveTool', { type: 'update selection', }), @@ -93,7 +82,7 @@ export const sketchSolveMachine = setup({ if (event.type === 'equip tool') { nameOfToolToSpawn = event.data.tool } else if ( - event.type === 'xstate.done.actor.tool' && + event.type === CHILD_TOOL_DONE_EVENT && context.pendingToolName ) { nameOfToolToSpawn = context.pendingToolName @@ -103,7 +92,7 @@ export const sketchSolveMachine = setup({ } return { - toolActor: typedSpawn(nameOfToolToSpawn, { id: 'tool' }), + toolActor: typedSpawn(nameOfToolToSpawn, { id: CHILD_TOOL }), sketchSolveToolName: nameOfToolToSpawn, pendingToolName: undefined, // Clear the pending tool after spawning } @@ -188,7 +177,7 @@ export const sketchSolveMachine = setup({ 'switching tool': { on: { - 'xstate.done.actor.tool': { + [CHILD_TOOL_DONE_EVENT]: { target: 'using tool', actions: [ () => console.log('switched tools with xstate.done.actor.tool'), @@ -209,7 +198,7 @@ export const sketchSolveMachine = setup({ 'unequipping tool': { on: { - 'xstate.done.actor.tool': { + [CHILD_TOOL_DONE_EVENT]: { target: 'move and select', actions: ['send tool unequipped to parent'], }, From 91391beb80c1206d42332369a0a935de97761990 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Fri, 3 Oct 2025 13:50:38 +1000 Subject: [PATCH 2/4] clean up --- src/machines/sketchSolve/sketchSolveMode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machines/sketchSolve/sketchSolveMode.ts b/src/machines/sketchSolve/sketchSolveMode.ts index 40b980a10bc..d1c3cc749da 100644 --- a/src/machines/sketchSolve/sketchSolveMode.ts +++ b/src/machines/sketchSolve/sketchSolveMode.ts @@ -90,9 +90,9 @@ export const sketchSolveMachine = setup({ console.error('Cannot determine tool to spawn') return {} } + typedSpawn(nameOfToolToSpawn, { id: CHILD_TOOL }) return { - toolActor: typedSpawn(nameOfToolToSpawn, { id: CHILD_TOOL }), sketchSolveToolName: nameOfToolToSpawn, pendingToolName: undefined, // Clear the pending tool after spawning } From 798e95db7f8bde5435ccfd7095230214104424f3 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Fri, 3 Oct 2025 13:51:47 +1000 Subject: [PATCH 3/4] clean up --- src/machines/sketchSolve/sketchSolveMode.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/machines/sketchSolve/sketchSolveMode.ts b/src/machines/sketchSolve/sketchSolveMode.ts index d1c3cc749da..83e72f82475 100644 --- a/src/machines/sketchSolve/sketchSolveMode.ts +++ b/src/machines/sketchSolve/sketchSolveMode.ts @@ -73,9 +73,6 @@ export const sketchSolveMachine = setup({ data: { tool: null }, }), 'spawn tool': assign(({ event, spawn, context }) => { - // this type-annotation informs spawn tool of the association between the EquipTools type and the machines in equipTools - // It's not an type assertion. TS still checks that _spawn is assignable to SpawnToolActor. - const typedSpawn: SpawnToolActor = spawn // Determine which tool to spawn based on event type let nameOfToolToSpawn: EquipTool @@ -90,6 +87,9 @@ export const sketchSolveMachine = setup({ console.error('Cannot determine tool to spawn') return {} } + // this type-annotation informs spawn tool of the association between the EquipTools type and the machines in equipTools + // It's not an type assertion. TS still checks that _spawn is assignable to SpawnToolActor. + const typedSpawn: SpawnToolActor = spawn typedSpawn(nameOfToolToSpawn, { id: CHILD_TOOL }) return { From 4cb0daee6006bea6e2b804cb0627159b1a9b5e82 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Fri, 3 Oct 2025 13:53:01 +1000 Subject: [PATCH 4/4] clean up --- src/machines/sketchSolve/sketchSolveMode.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/machines/sketchSolve/sketchSolveMode.ts b/src/machines/sketchSolve/sketchSolveMode.ts index 83e72f82475..3c216293554 100644 --- a/src/machines/sketchSolve/sketchSolveMode.ts +++ b/src/machines/sketchSolve/sketchSolveMode.ts @@ -22,8 +22,8 @@ const equipTools = Object.freeze({ pointTool, }) -const CHILD_TOOL = 'child tool' -const CHILD_TOOL_DONE_EVENT = `xstate.done.actor.${CHILD_TOOL}` +const CHILD_TOOL_ID = 'child tool' +const CHILD_TOOL_DONE_EVENT = `xstate.done.actor.${CHILD_TOOL_ID}` export type EquipTool = keyof typeof equipTools @@ -53,8 +53,8 @@ export const sketchSolveMachine = setup({ events: {} as SketchSolveMachineEvent, }, actions: { - 'send unequip to tool': sendTo(CHILD_TOOL, { type: 'unequip' }), - 'send update selection to equipped tool': sendTo(CHILD_TOOL, { + 'send unequip to tool': sendTo(CHILD_TOOL_ID, { type: 'unequip' }), + 'send update selection to equipped tool': sendTo(CHILD_TOOL_ID, { type: 'update selection', }), 'send updated selection to move tool': sendTo('moveTool', { @@ -90,7 +90,7 @@ export const sketchSolveMachine = setup({ // this type-annotation informs spawn tool of the association between the EquipTools type and the machines in equipTools // It's not an type assertion. TS still checks that _spawn is assignable to SpawnToolActor. const typedSpawn: SpawnToolActor = spawn - typedSpawn(nameOfToolToSpawn, { id: CHILD_TOOL }) + typedSpawn(nameOfToolToSpawn, { id: CHILD_TOOL_ID }) return { sketchSolveToolName: nameOfToolToSpawn,