Skip to content

Instantly share code, notes, and snippets.

@irishbryan
Created July 2, 2020 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irishbryan/5ed0b6eb641f3dafcfb718131cfdc0a7 to your computer and use it in GitHub Desktop.
Save irishbryan/5ed0b6eb641f3dafcfb718131cfdc0a7 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 increment = assign({
count: (context, event) => context.count + 1
})
const fetchMachine = Machine({
id: 'toggle',
context: {
count: 0
},
initial: 'inactive',
states: {
inactive: {
on: {
TOGGLE: {
target: 'active',
actions: increment
}
},
},
active: {
on: {
TOGGLE: {
target: 'inactive',
actions: increment,
cond: "countWatcher",
},
}
}
}
},
{
guards: {
countWatcher: (context, event) => {
return context.count < 5
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment