Skip to content

Instantly share code, notes, and snippets.

@stephencweiss
Last active September 12, 2020 15:11
Show Gist options
  • Save stephencweiss/af30bc416ea9538526a3bc9c8e515e9b to your computer and use it in GitHub Desktop.
Save stephencweiss/af30bc416ea9538526a3bc9c8e515e9b 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 submissionPost = () => {
return fetch('').then(res => res.json)
}
const editing = {
on: {
beginReview: 'review',
update: {
target: '',
actions: ['update']
}
}
}
const review = {
on: {
confirm: {
target: 'loading'
}
}
}
const loading = {
invoke: {
id: 'submissionPost',
src: submissionPost,
onDone: {
target: 'success',
actions: assign({
data: (context, event) => event.data
})
},
onError: {
target: 'failure',
actions: assign({
error: (context, event) => event.data
})
}
}
}
const success = {}
const failure = {}
const customStates = {editing, review, loading, success, failure}
const context = {
data: null,
errors: null,
count: 0
}
const fetchMachine = Machine({
id: 'fetch',
initial: 'editing',
context ,
states: {
...customStates
}
}, {actions: {
update: assign((context, event) => {
console.log(event)
return event.payload})
}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment