Skip to content

Instantly share code, notes, and snippets.

@keithernet
Created June 15, 2021 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithernet/a9e1b4a852b1de8c8eddc0895cb6435d to your computer and use it in GitHub Desktop.
Save keithernet/a9e1b4a852b1de8c8eddc0895cb6435d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const newMachine = {
id: 'newProduct',
initial: 'idle',
states: {
idle: {
on: {
save: 'saving'
}
},
saving: {
type: 'final'
}
}
};
const fetchMachine = Machine({
id: 'fetch',
initial: 'showingList',
context: {
products: []
},
states: {
showingList: {
on: {
newClicked: 'creatingNew'
}
},
creatingNew: {
invoke: {
src: newMachine,
onDone: {
target: 'saved'
}
}
},
saved: {
entry: 'addNewItem',
always: {
target: 'showingList'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment