Skip to content

Instantly share code, notes, and snippets.

@rakeshmenon
Created May 15, 2020 17:11
Show Gist options
  • Save rakeshmenon/8066d7d00f2c881794021e0fc4b846dc to your computer and use it in GitHub Desktop.
Save rakeshmenon/8066d7d00f2c881794021e0fc4b846dc to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetch',
initial: 'loading',
context: {
data: {},
error: {},
},
states: {
loading: {
invoke: {
src: 'fetchData',
onDone: {
target: 'success',
actions: assign({
data: (_, event) => event.data,
}),
},
onError: {
target: 'failure',
actions: assign({
error: (_, event) => event.data,
}),
},
},
},
success: {
entry: 'postSuccess',
on: {
'': {
target: 'collapsed'
}
}
},
failure: {
type: 'final',
},
collapsed: {
entry: ['onCollapsed'],
on: {
'EXPAND': {
target: 'expanded'
},
'FETCH': {
target: 'loading'
},
}
},
expanded: {
entry: ['onExpand'],
on: {
'COLLAPSE': {
target: 'collapsed'
},
'FETCH': {
target: 'loading'
},
}
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment