Last active
May 30, 2020 20:10
-
-
Save marcmartino/76c995114ff784dc9e90ac31bfa7ffe5 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 clearTranscriptNodes = assign({ | |
speechNodeTranscript: {}, | |
listeningNodeTranscript: {}, | |
}); | |
const setSpeechNodeContext = (lang, text) => | |
assign({ | |
speechNodeTranscript: { | |
text, | |
lang, | |
}, | |
}); | |
const setListenNodeContext = (lang, responses) => | |
assign({ | |
listeningNodeTranscript: { | |
responses, | |
lang, | |
}, | |
}); | |
const speechMachine = Machine({ | |
id: "Flashcard", | |
initial: "selectedWordList", | |
strict: true, | |
context: { | |
speechNodeTranscript: {}, | |
listeningNodeTranscript: {}, | |
trancriptContext: {}, | |
}, | |
states: { | |
selectedWordList: { | |
on: { | |
FETCH: { target: "card.loadingQueuedWords" }, | |
}, | |
}, | |
card: { | |
id: "card", | |
states: { | |
loadingQueuedWords: { | |
on: { | |
RESOLVE: { target: "presentFlashcard" }, | |
REJECT: { target: "failure" }, | |
}, | |
}, | |
presentFlashcard: { | |
entry: setSpeechNodeContext("es-AR", "la palabra"), | |
exit: clearTranscriptNodes, | |
on: { | |
SUPPLY_ANSWER: { target: "answerSupplied" }, | |
CARD_RESOURCES_STATEMENT: { | |
target: "#cardResources.describeCardResource", | |
}, | |
HELP_STATEMENT: { target: "#help.entry" }, | |
APP_NAVIGATION_STATEMENT: { target: "#appNav.root" }, | |
}, | |
}, | |
answerSupplied: { | |
on: { | |
CORRECT: { target: "loadingQueuedWords" }, | |
INCORRECT: { target: "presentFlashcard" }, | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
failure: { | |
type: "final", | |
}, | |
}, | |
}, | |
cardResourceMenu: { | |
id: "cardResources", | |
states: { | |
describeCardResource: { | |
on: { | |
REQ_PREV: { target: "describeCardResource" }, | |
REQ_FORWARD: { target: "describeCardResource" }, | |
REQ_DEFINITION: { target: "definition" }, | |
REQ_EXAMPLE_SENTENCES: { target: "sentences" }, | |
REQ_CONJUGATIONS: { target: "conjugations" }, | |
RETURN: { target: "#card.presentFlashcard" }, | |
}, | |
}, | |
definition: { | |
on: { | |
REQ_PREV: { target: "describeCardResource" }, | |
REQ_FORWARD: { target: "describeCardResource" }, | |
REQ_EXAMPLE_SENTENCES: { target: "sentences" }, | |
REQ_CONJUGATIONS: { target: "conjugations" }, | |
RETURN: { target: "#card.presentFlashcard" }, | |
}, | |
}, | |
sentences: { | |
on: { | |
REQ_PREV: { target: "describeCardResource" }, | |
REQ_FORWARD: { target: "describeCardResource" }, | |
REQ_DEFINITION: { target: "definition" }, | |
REQ_CONJUGATIONS: { target: "conjugations" }, | |
RETURN: { target: "#card.presentFlashcard" }, | |
}, | |
}, | |
conjugations: { | |
on: { | |
REQ_PREV: { target: "describeCardResource" }, | |
REQ_FORWARD: { target: "describeCardResource" }, | |
REQ_DEFINITION: { target: "definition" }, | |
REQ_EXAMPLE_SENTENCES: { target: "sentences" }, | |
RETURN: { target: "#card.presentFlashcard" }, | |
}, | |
}, | |
}, | |
}, | |
helpMenu: { | |
id: "help", | |
states: { | |
entry: { | |
type: "final", | |
}, | |
}, | |
}, | |
appNavigationMenu: { | |
id: "appNav", | |
states: { | |
root: { | |
on: { | |
NEXT: { target: "nextConfirmation" }, | |
PAUSE: { target: "paused" }, | |
EXIT: { target: "exiting" }, | |
}, | |
}, | |
paused: { | |
on: { | |
UNPAUSE: { target: "#card.presentFlashcard" }, | |
}, | |
}, | |
nextConfirmation: { | |
entry: assign({ | |
speechNodeTranscript: { | |
lang: "en-US", | |
text: "Next Word", | |
}, | |
}), | |
exit:clearTranscriptNodes, | |
on: { | |
NEXT_WORD: { target: "#card.loadingQueuedWords" }, | |
}, | |
}, | |
exiting: { | |
type: "final", | |
}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment