Skip to content

Instantly share code, notes, and snippets.

@renerbaffa
Last active April 29, 2020 08:21
Show Gist options
  • Save renerbaffa/b7f25426840463535b081cca7a1015d3 to your computer and use it in GitHub Desktop.
Save renerbaffa/b7f25426840463535b081cca7a1015d3 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 { cancel } = actions
function fetchUsers() {}
function saveChanges() {}
const fetchMachine = Machine({
id: 'multi-admin',
initial: 'fetch-users',
context: {
allUsers: [],
selected: [],
},
states: {
'fetch-users' : {
invoke: {
src: () => fetchUsers,
onError: 'fetch-error',
onDone: 'selection',
}
},
'fetch-error': {
on: {
RETRY: 'fetch-users'
}
},
selection: {
type: 'parallel',
states: {
active: {
initial: 'selecting',
states: {
selecting: {
on: {
SELECT: {
actions: [
assign({
selected: context => context.selected,
}),
cancel('debounce'),
send('SAVE', { id: 'debounce', delay: 2000 }),
],
},
},
},
},
},
sync: {
initial: 'idle',
states: {
idle: {
on: {
SAVE: 'saving'
},
},
saving: {
invoke: {
id: 'saving',
src: context => saveChanges(),
onDone: 'idle',
onError: 'error',
},
},
error: {},
},
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment