Skip to content

Instantly share code, notes, and snippets.

@snikch
Created November 30, 2020 01:13
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/a5f599dabb8483dcf68d9042b1bafd43 to your computer and use it in GitHub Desktop.
Save snikch/a5f599dabb8483dcf68d9042b1bafd43 to your computer and use it in GitHub Desktop.
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const accessHandshake = {
id: 'fetch',
initial: 'requested',
states: {
requested: {
invoke: {
src: 'checkPin',
onDone: {
target: 'accepting'
},
onError: {} // Nothing
},
on: {
ACCEPT: 'accepting',
REJECT: 'rejected'
}
},
accepting: {
on: {
RESOLVE: 'accepted',
REJECT: 'errored'
}
},
accepted: {
invoke: {
src: 'respond',
onDone: {
target: "#fetch.waiting"
}
}
},
rejected: {
invoke: {
src: 'respond',
onDone: {
target: "#fetch.waiting"
}
} },
errored: {
invoke: {
src: 'respond',
onDone: {
target: "#fetch.waiting"
}
}
}
}
}
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
on: {
DISABLE: 'idle'
},
states: {
idle: {
on: {
ENABLE: 'initialising'
}
},
initialising: {
invoke: {
src: 'startInterface',
onDone: {
target: 'waiting'
},
onError: {
target: 'failed'
}
}
},
failed: {
type: 'final'
},
waiting: {
on: {
REQUEST_RECEIVED: 'handshaking'
}
},
handshaking: accessHandshake
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment