Skip to content

Instantly share code, notes, and snippets.

@mwangaben
Last active August 12, 2021 20:10
Show Gist options
  • Save mwangaben/b0483f13c993ac44570d99b91887a74f to your computer and use it in GitHub Desktop.
Save mwangaben/b0483f13c993ac44570d99b91887a74f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'fetch',
initial: 'show',
context: {
user: '',
error: '',
},
states: {
show: {
on: {
EDIT: 'edit'
}
},
edit: {
on: {
UPDATE: {target: 'update'},
CANCEL: {target: 'cancel'}
}
},
update: {
invoke: {
id: 'user-id',
src: (contex,event) => update(context, event),
onDone: {
target: 'success',
actions: assign({user:(_ctx, event) => event.data})
},
onError:{
target: 'error',
actions: assign({error: (_ctx, event) => event.data})
}
}
},
error: {
after: {
2000: {target: 'show'}
}
},
cancel:{
after: {
200:
{target: 'show'}
}
},
success: {
after: {
2000: {target: 'show'}
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment