Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 14, 2020 18:35
Show Gist options
  • Save christiannwamba/b12aa27b431e66d9fd06233cbe10a039 to your computer and use it in GitHub Desktop.
Save christiannwamba/b12aa27b431e66d9fd06233cbe10a039 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
//DEMO: Delay Events and
// Use after instead of `on` for timer events
const states = {
green: {
after: {
RED_TIMER: 'yellow'
}
},
yellow: {
after: {
YELLOW_TIMER: 'red'
}
},
red: {
after: {
GREEN_TIMER: 'green'
}
}
}
const options = {
delays: {
GREEN_TIMER: 4000,
YELLOW_TIMER: 1000,
// Can take a function
RED_TIMER: (context, events) => 3000
}
}
const fetchMachine = Machine({
id: 'stopLight',
initial: 'red',
states
}, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment