Skip to content

Instantly share code, notes, and snippets.

@snikch
Last active November 30, 2020 04:26
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 snikch/8474779f2dd17bdbedc7d3448f73b103 to your computer and use it in GitHub Desktop.
Save snikch/8474779f2dd17bdbedc7d3448f73b103 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: 'connect',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
CONNECT: 'init'
}
},
init: {
invoke: {
src: 'initInterface',
onError: {
target: 'idle',
actions: 'setErroredMessage'
},
onDone: {
target: 'prompting'
}
}
},
prompting: {
on: {
REQUEST_WITHOUT_PIN: 'requesting',
REQUEST_WITH_PIN: {
target:'requesting',
cond: 'isPinEntered'
},
CANCEL: 'idle'
}
},
requesting: {
invoke: {
src: 'requestAccess',
},
on: {
ACCEPTED: 'connecting',
REJECTED: {
target: 'idle',
actions: 'setRejectionMessage'
},
ERRORED: {
target: 'idle',
actions: 'setErroredMessage'
},
CANCEL: 'idle'
}
},
connecting: {
invoke: {
src: 'connect',
onDone: {
target: 'connected'
},
onError: {
target: 'idle',
actions: 'setErroredMessage'
}
},
on: {
CANCEL: 'idle'
}
},
connected: {
on: {
DISCONNECT: {
target: 'idle',
actions: 'disconnect'
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment