Skip to content

Instantly share code, notes, and snippets.

@snikch
Last active December 3, 2020 04:55
Show Gist options
  • Save snikch/520f6b0c85bce4ef06c9d50d49f9d69a to your computer and use it in GitHub Desktop.
Save snikch/520f6b0c85bce4ef06c9d50d49f9d69a 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 accessHandshake = {
id: 'fetch',
initial: 'requested',
states: {
requested: {
invoke: {
src: 'checkRequest',
onDone: {
target: 'accepting'
},
onError: {
target: 'errored'
} // Nothing
},
on: {
ACCEPT: 'accepting',
REJECT: 'rejected'
}
},
accepting: {
invoke: {
src: 'addPeer',
onDone: {
target: 'accepted'
},
onError: {
target: '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: 'initInterface',
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