Last active
April 29, 2020 08:21
-
-
Save renerbaffa/b7f25426840463535b081cca7a1015d3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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