Skip to content

Instantly share code, notes, and snippets.

@rojoca
Last active March 4, 2020 20:24
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 rojoca/e82aa90129ceb8530c4db4e7661817ce to your computer and use it in GitHub Desktop.
Save rojoca/e82aa90129ceb8530c4db4e7661817ce to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - assign
// - interpret
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const inertiaMachine = Machine({
id: 'inertia',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
INIT: {
target: 'loading',
actions: [
assign({
page: (context, event) => event.page
}),
'progressIncrement'
]
}
}
},
loading: {
on: {
RESOLVE: {
target: 'ready'
}
}
},
ready: {
on: {
VISIT: {
target: 'requesting'
}
}
},
hardVisit: {
type: 'final'
},
rejected: {
type: 'final'
},
modal: {
on: {
CLOSE_MODAL: {
target: 'ready'
}
}
},
requesting: {
entry: [
'startProgress',
'cancelActive',
'createVisit'
],
on: {
VISIT: {
target: 'requesting',
},
RESPONSE: {
target: 'loading'
},
ERROR: [
{
target: 'ready',
cond: 'isCancelled'
},
{
target: 'hardVisit',
cond: 'isConflict',
actions: [
'progressStop',
assign({
location: (context, event) => event.error.response.headers['x-inertia-location'],
replace: true
})
]
},
{
target: 'ready',
cond: 'isInertiaErrorResponse'
},
{
target: 'modal',
cond: 'isModalError'
},
{ target: 'rejected' }
]
}
}
}
},
{
actions: {
progressStart: (context, event) => {
Progress.start();
},
progressIncrement: (context, event) => {
Progress.increment();
},
progressStop: (context, event) => {
Progress.stop();
}
},
guards: {
isCancelled: (context, event) => {
// Axios.isCancel(event.error)
return false;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment