Skip to content

Instantly share code, notes, and snippets.

@dra1n
Last active December 7, 2020 13:20
Show Gist options
  • Select an option

  • Save dra1n/1f3f0f1007de761c9cf2d2eea3e19341 to your computer and use it in GitHub Desktop.

Select an option

Save dra1n/1f3f0f1007de761c9cf2d2eea3e19341 to your computer and use it in GitHub Desktop.
const events = {
RIDE: "RIDE",
RIDE_TAXI: "RIDE_TAXI",
RIDE_BUS: "RIDE_BUS",
WALK: "WALK"
}
const getHomeMachine = Machine({
type: 'parallel',
states: {
riding_enabled: {
initial: 'no',
states: {
yes: {},
no: {
on: {
[events.RIDE]: 'yes'
}
}
}
},
global: {
initial: 'walking',
on: {
[events.RIDE_TAXI]: 'global.riding.taxi',
[events.RIDE_BUS]: 'global.riding.bus'
},
states: {
idle: {
on: {
[events.RIDE]: 'riding',
[events.WALK]: 'walking'
}
},
walking: {
on: {
[events.RIDE]: 'riding',
[events.WALK]: 'idle'
}
},
riding: {
initial: 'bus',
on: {
[events.WALK]: 'walking',
[events.RIDE]: 'idle',
},
states: {
bus: {},
taxi: {}
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment