Skip to content

Instantly share code, notes, and snippets.

@BensonMwaura
Last active January 6, 2020 10:12
Show Gist options
  • Save BensonMwaura/05b0ea818a1fa4077e3405c8bd23e63e to your computer and use it in GitHub Desktop.
Save BensonMwaura/05b0ea818a1fa4077e3405c8bd23e63e 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: 'landing',
initial: 'skeleton',
context: {
retries: 0
},
states: {
skeleton: {
on: {
FETCH: 'start'
}
},
start: {
on: {
REQUEST: 'demo'
}
},
demo: {
on: {
SUBMIT: 'loading',
CANCEL: 'start'
}
},
loading: {
on: {
RESOLVE: 'results',
REJECT: 'error'
}
},
error: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) =>
context.retries + 1
})
}
}
},
results: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'results',
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