chore: cleaning up useless state transition to be an on event direct to action state

This commit is contained in:
Kevin Nadro
2025-04-04 16:00:47 -05:00
parent 983d6160d1
commit 9d673d1903
2 changed files with 13 additions and 28 deletions

View File

@ -69,6 +69,9 @@ export const useSettings = () =>
// TODO: Debugging
const systemIOActor = appActor.getSnapshot().children.systemIO!
// systemIOActor.send({type:SystemIOMachineEvents.readFoldersFromProjectDirectory, data: {}})
systemIOActor.send({type:SystemIOMachineEvents.setProjectDirectoryPath, data: {requestedProjectDirectoryPath:'/home/kevin-nadro/Documents/zoo-modeling-app-projects'}})
window.systemIOActor = systemIOActor

View File

@ -1,7 +1,7 @@
import { setup, fromPromise, assign, assertEvent} from 'xstate'
import { DEFAULT_PROJECT_NAME } from "@src/lib/constants"
import { mkdirOrNOOP, getProjectInfo } from "@src/lib/desktop"
import type { FileEntry, Project } from '@src/lib/project'
import type { Project } from '@src/lib/project'
export enum SystemIOMachineActors {
readFoldersFromProjectDirectory = "read folders from project directory",
@ -20,7 +20,6 @@ export enum SystemIOMachineEvents {
readFoldersFromProjectDirectory = "read folders from project directory",
done_readFoldersFromProjectDirectory = donePrefix + "read folders from project directory",
setProjectDirectoryPath = "set project directory path",
done_setProjectDirectoryPath = donePrefix + "set project directory path",
}
export enum SystemIOMachineActions {
@ -56,7 +55,6 @@ export const systemIOMachine = setup({
| { type: SystemIOMachineEvents.readFoldersFromProjectDirectory; data: {} }
| { type: SystemIOMachineEvents.done_readFoldersFromProjectDirectory; data: {}, output: Project[] }
| { type: SystemIOMachineEvents.setProjectDirectoryPath; data: {requestedProjectDirectoryPath: string}}
| { type: SystemIOMachineEvents.done_setProjectDirectoryPath; data: {requestedProjectDirectoryPath: string}, output: string}
},
actions: {
[SystemIOMachineActions.setFolders]: assign({
@ -67,8 +65,8 @@ export const systemIOMachine = setup({
}),
[SystemIOMachineActions.setProjectDirectoryPath]: assign({
projectDirectoryPath:({event})=>{
assertEvent(event, SystemIOMachineEvents.done_setProjectDirectoryPath)
return event.output
assertEvent(event, SystemIOMachineEvents.setProjectDirectoryPath)
return event.data.requestedProjectDirectoryPath
}
})
},
@ -110,9 +108,6 @@ export const systemIOMachine = setup({
}
return projects
}),
[SystemIOMachineActors.setProjectDirectoryPath]: fromPromise(async ({input}:{input: string}) => {
return input
})
}
}).createMachine({
initial:SystemIOMachineStates.idle,
@ -128,8 +123,14 @@ export const systemIOMachine = setup({
states: {
[SystemIOMachineStates.idle]: {
on: {
// on can be an action
[SystemIOMachineEvents.readFoldersFromProjectDirectory]:SystemIOMachineStates.readingFolders,
[SystemIOMachineEvents.setProjectDirectoryPath]:SystemIOMachineStates.settingProjectDirectoryPath
[SystemIOMachineEvents.setProjectDirectoryPath]:{
target: SystemIOMachineStates.readingFolders,
actions: [
SystemIOMachineActions.setProjectDirectoryPath
]
}
}
},
[SystemIOMachineStates.readingFolders]: {
@ -150,25 +151,6 @@ export const systemIOMachine = setup({
}
}
},
[SystemIOMachineStates.settingProjectDirectoryPath]: {
invoke: {
id: SystemIOMachineActors.setProjectDirectoryPath,
src: SystemIOMachineActors.setProjectDirectoryPath,
input: ({event}) => {
assertEvent(event, SystemIOMachineEvents.setProjectDirectoryPath)
return event.data.requestedProjectDirectoryPath
},
onDone: {
target: SystemIOMachineStates.readingFolders,
actions: [
SystemIOMachineActions.setProjectDirectoryPath
]
},
onError: {
target: SystemIOMachineStates.idle,
}
}
}
}
})