Skip to content

Instantly share code, notes, and snippets.

@bmsterling
Last active March 2, 2021 19:05
Show Gist options
  • Save bmsterling/22427c79f33cdaaabeee557739482577 to your computer and use it in GitHub Desktop.
Save bmsterling/22427c79f33cdaaabeee557739482577 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 EnumStatesType = {
closing: '@state/closing',
done: '@state/done',
error: '@state/error',
idle: '@state/idle',
loading: '@state/loading',
opened: '@state/opened',
opening: '@state/opening',
preview: '@state/preview',
resetting: '@state/resetting',
reloadSuccess: '@state/reloadSuccess',
}
const FETCH = '@action/FETCH';
const fetchMachine = Machine({
id: 'fetch',
initial: EnumStatesType.idle,
context: {
retries: 0
},
states: {
[EnumStatesType.idle]: {
on: {
[FETCH]: EnumStatesType.loading
}
},
[EnumStatesType.loading]: {
on: {
RESOLVE: EnumStatesType.success,
REJECT: EnumStatesType.error
}
},
[EnumStatesType.success]: {
type: 'final'
},
[EnumStatesType.error]: {
on: {
RETRY: {
target: EnumStatesType.loading,
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