Skip to content

Instantly share code, notes, and snippets.

@lazybean
Last active May 12, 2021 09:44
Show Gist options
  • Save lazybean/95966efea2b5510b6cc30a4a13215c0e to your computer and use it in GitHub Desktop.
Save lazybean/95966efea2b5510b6cc30a4a13215c0e 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: 'simulation',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
SIMULATE: 'creating'
}
},
creating: {
entry: ['createPlaceholder'],
exit: ['removePlaceholder'],
on: {
RESOLVE: 'polling',
REJECT: 'failure'
},
},
polling: {
on: {
SUCCESS: 'success',
RUNNING: 'polling',
},
initial: 'idle',
states: {
idle: {
on: {
'after 5s': 'request'
}
},
request: {
on: {
response: 'response'
}
},
response: {
on: {
'after 5s': 'request'
}
},
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'creating',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment