Skip to content

Instantly share code, notes, and snippets.

@kdgerona
Last active November 9, 2020 02:46
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 kdgerona/b140d5c8c4156ad6cea06e9f86e35517 to your computer and use it in GitHub Desktop.
Save kdgerona/b140d5c8c4156ad6cea06e9f86e35517 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: 'fetch',
initial: 'idle',
context: {
retries: 0
},
on: {
SEND_TEST: {
actions: send('SAMPLE', {to : 'loading'})
}
},
states: {
idle: {
on: {
FETCH: 'loading',
// SEND_TEST: {
// actions: send('SAMPLE')
// }
}
},
loading: {
id: 'loading',
on: {
RESOLVE: 'loading.ready',
REJECT: 'failure'
},
initial: 'idle',
states: {
idle: {
on:{
SAMPLE: {
actions: () => console.log('Im here')
}
}
},
ready: {
on: {
"": 'processing'
}
},
processing: {
on: {
"": '#fetch.success'
}
}
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: '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