Skip to content

Instantly share code, notes, and snippets.

@cblanc
Created January 4, 2021 04:52
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 cblanc/8294eabe0f513a72aa270e809ca81ba9 to your computer and use it in GitHub Desktop.
Save cblanc/8294eabe0f513a72aa270e809ca81ba9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const INPUT = { INPUT: { actions: "input" } };
const CLOSE = { CLOSE: "closed" };
const SUGGEST = { SUGGEST: "suggesting" };
const NOTIFY = { NOTIFY: "notifying" };
const fetchMachine = Machine({
initial: "closed",
context: {
suggestions: [],
message: "Start typing to find address",
},
states: {
closed: {
entry: ["close", "onClose"],
exit: ["onOpen", "open"],
on: {
AWAKE: [
{
target: "suggesting",
cond: (c) => c.suggestions.length > 0,
},
{
target: "notifying",
},
],
},
},
notifying: {
entry: ["updateMessage", "showMessage"],
on: {
...CLOSE,
...SUGGEST,
...NOTIFY,
...INPUT,
},
},
suggesting: {
entry: ["updateSuggestions", "renderSuggestions"],
on: {
...CLOSE,
...SUGGEST,
...NOTIFY,
...INPUT,
NEXT: { actions: "next" },
PREVIOUS: { actions: "previous" },
SELECT: { actions: "select" },
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment