Skip to content

Instantly share code, notes, and snippets.

@austinsamsel
Last active May 5, 2021 14:04
Show Gist options
  • Save austinsamsel/ab4de076e90902b481e37c88d025a18e to your computer and use it in GitHub Desktop.
Save austinsamsel/ab4de076e90902b481e37c88d025a18e 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 fcl = {decode: () => {}}
const guards = {
isPolling: (ctx) => true, // ctx.poll,
};
const POLL_DELAY = 1000;
const machineDef = {
id: 'script',
initial: 'idle',
context: {
decoder: fcl.decode,
ix: undefined,
poll: false,
result: undefined,
error: undefined,
},
states: {
idle: {
on: {
send: {
target: 'sending',
actions: 'assignSendData',
},
},
},
sending: {
invoke: {
src: 'fclSend',
onDone: [
{
target: 'done',
actions: 'assignScriptResult',
},
],
onError: {
target: '#error',
actions: 'assignError',
},
},
},
polling: {
initial: 'waiting',
states: {
waiting: {
after: {
POLL_DELAY: 'sending',
},
},
sending: {
invoke: {
src: 'fclSend',
onDone: {
target: 'waiting',
actions: 'assignScriptResult',
},
onError: {
target: '#error',
actions: 'assignError',
},
},
},
},
on: {
stop: {
target: 'done',
actions: 'assignStopData',
},
},
},
done: {
always: {
target: 'polling',
cond: 'isPolling',
},
on: {
send: 'sending',
},
},
error: {
id: 'error',
on: {
send: 'sending',
},
},
},
on: {
error: 'error',
},
};
const machine = Machine(
machineDef,
{
delays: { POLL_DELAY },
guards,
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment