Skip to content

Instantly share code, notes, and snippets.

@jeremy-green
Last active September 13, 2019 22:20
Show Gist options
  • Save jeremy-green/04ffd9e1d431fc1074ee5a91fc22a046 to your computer and use it in GitHub Desktop.
Save jeremy-green/04ffd9e1d431fc1074ee5a91fc22a046 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
new Machine(
{
id: 'weather',
initial: 'boot',
states: {
boot: {
on: {
PRECIPITATION: { target: 'precipitation', actions: ['notify'] },
NO_PRECIPITATION: { target: 'no_precipitation', actions: ['notify'] },
REJECTED: { target: 'boot', actions: ['rejected'] },
},
},
no_precipitation: {
on: {
PRECIPITATION: { target: 'precipitation', actions: ['notify'] },
REJECTED: { target: 'no_precipitation', actions: ['rejected'] },
},
},
precipitation: {
on: {
NO_PRECIPITATION: { target: 'no_precipitation', actions: ['notify'] },
REJECTED: { target: 'precipitation', actions: ['rejected'] },
},
},
},
},
{
actions: {
notify(context, { status, currently }) {
console.log('precipitation', { status, currently });
},
rejected(context, event) {
console.log('rejected', context, event);
},
},
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment