Created
July 2, 2020 13:47
-
-
Save irishbryan/5ed0b6eb641f3dafcfb718131cfdc0a7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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