Last active
April 10, 2021 00:12
-
-
Save bfunc/2304aa449fed4cdc8d90224ae19731b2 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
const redditMachine = Machine( | |
{ | |
id: 'reddit', | |
initial: 'idle', | |
context: { | |
question: 'em', | |
}, | |
states: { | |
idle: { | |
on: { | |
LOAD: { | |
target: 'loading', | |
actions: assign({ | |
question: (context, event) => context.question += '?' | |
}) | |
} | |
}, | |
}, | |
loading: { | |
on: { | |
ANSWER_RIGHT: 'success', | |
ANSWER_WRONG: 'failure' | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'loading', | |
actions: assign({ | |
question: (context, event) => context.question += '!' | |
}) | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment