Skip to content

Instantly share code, notes, and snippets.

@danielmarquesr
Created April 14, 2021 19:39
Show Gist options
  • Save danielmarquesr/3feefbbd05df90ce21c9adda4ccf95d2 to your computer and use it in GitHub Desktop.
Save danielmarquesr/3feefbbd05df90ce21c9adda4ccf95d2 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 deviceMachine = Machine({
initial: 'idle',
context: {
device: null,
},
states: {
idle: {
on: {
CONNECT: {
target: 'connection',
actions: assign({ device: (_, e) => e.device }),
// cond: (context) => context.device,
},
},
},
connection: {
},
on: {
RESOLVE: {
target: 'connected',
},
},
},
connected: {
on: {
RUN: {
target: 'running',
},
},
},
running: {
on: {
DONE: {
target: 'connected',
},
},
},
});
const parentMachine = Machine({
initial: 'idle',
states: {
idle: {
on: {
TOGGLE_ON: {
target: 'scan',
},
},
},
scan: {
invoke: {
src: () => (cb) => {
cb({ type: 'CONNECT_RIGHT', device: {eae: 99} });
},
},
on: {
CONNECT_RIGHT: {
target: 'rightDevice',
},
},
},
rightDevice: {
invoke: {
id: 'rightDevice',
src: deviceMachine,
},
on: {
CONNECT: {
actions: send({ type: 'CONNECT', device: {eae: 1} }, { to: 'rightDevice' }),
},
},
},
},
on: {
TOGGLE_OFF: {
target: 'idle',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment