Skip to content

Instantly share code, notes, and snippets.

@chukinas
Created May 7, 2020 20:40
Show Gist options
  • Save chukinas/90402ec2c1f24eae3a0ca88037f4e21c to your computer and use it in GitHub Desktop.
Save chukinas/90402ec2c1f24eae3a0ca88037f4e21c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const buttonFactory = id => {
const toggleName = `TOGGLE${id}`
return {
id: `button${id}`,
initial: 'hist',
states: {
off: {
on: {
[toggleName]: 'on'
}
},
on: {
on: {
[toggleName]: 'off'
}
},
hist: {
type: 'history',
target: 'off',
history: 'deep',
},
},
}
}
const buttons = {
id: 'buttons',
type: 'parallel',
states: {
button1: buttonFactory(1),
button2: buttonFactory(2),
},
on: {
SLEEP: '#idle',
}
}
const parallelTest = Machine({
id: 'test',
initial: 'idle',
states: {
idle: {
id: 'idle',
on: {
START: 'buttons',
}
},
buttons,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment