Skip to content

Instantly share code, notes, and snippets.

@uliang
Last active October 16, 2019 02:40
Show Gist options
  • Select an option

  • Save uliang/452f55ba92e1f17a6f89c27d77682bac to your computer and use it in GitHub Desktop.

Select an option

Save uliang/452f55ba92e1f17a6f89c27d77682bac to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const Application = Machine({
id: 'app',
initial: 'ready',
states: {
ready: {
initial: 'ok',
on: {
NewGame: "characterCreation",
LoadGame: 'loadCharacter'
},
states: {
ok: {},
error: {}
}
},
characterCreation: {
initial: 'begin',
entry: ['spawnNewPC', 'spawnAC'],
states: {
begin: {
on: {
GetBookList: 'loading'
},
},
loading: {
invoke: {
id: 'fetchBookList',
src: 'fetchBookListPromise',
onDone: {
target:'#app.bookList',
actions: ['assignBookList']
},
onError: {
target:'#app.ready.error',
actions:['stopNewPC', 'stopAC']
}
}
},
}
},
bookList: {
on: {
UpdateBookChoice: {
target: 'construction',
actions: ['spawnBook']
}
}
},
construction: {
invoke: {
id: 'newCharacterFactory',
src: 'newCharacterFactoryMachine',
onDone: 'saving'
},
exit: ['stopNewPC']
},
saving: {
entry: ['sendSaveData'],
on: {
Success: 'playing'
},
exit: ['spawnReturningPC']
},
loadCharacter: {
initial: 'begin',
entry: ['spawnReturningPC'],
states: {
begin: {
on: {
GetPreviousSaves: 'loading'
}
},
loading: {
invoke:{
id: 'fetchSavedGames',
src: 'fetchSavedGamesPromise',
onError: {
target: '#app.ready.error',
actions: ['stopReturningPC'],
},
onDone: {
target:'display',
actions: ['assignSavedGameList']
}
}
},
display: {
on: {
LoadGame: '#app.loading'
}
}
}
},
loading: {
invoke: {
id: 'fetchThisGame',
src: 'fetchThisGamePromise',
onError: {
target: '#app.loadCharacter',
actions: ['stopReturningPC']
},
onDone: {
target:'playing',
actions: ['spawnAC', 'spawnBook']
}
}
},
playing: {
on: {
Save: 'saving',
SaveNQuit: {
target: 'cleanup'
}
},
exit:['stopReturningPC']
},
cleanup: {
entry: ['sendSaveData'],
exit: ['stopBook', 'stopAC'],
on: {
Success: '#app.ready'
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment