Skip to content

Instantly share code, notes, and snippets.

@mcky
Created March 17, 2021 11:50
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 mcky/e26659bdcc0a39a8352931c81ebad93f to your computer and use it in GitHub Desktop.
Save mcky/e26659bdcc0a39a8352931c81ebad93f 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 fetchStates = () => ({
// id: 'fetch',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
READY: {
target: '#captions.ready',
cond: () => true
},
COMPLETE: {
target: '#captions.complete',
cond: () => true
},
REJECT: 'failure'
}
},
success: {
// type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
})
const fetchMachine = Machine({
id: 'captions',
initial: 'unknown',
states: {
unknown: {
on: {
FETCH: 'fetching'
}
},
fetching: {
// on: {
// FETCH: 'ready'
// },
...fetchStates()
},
ready: {},
complete: {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment