Skip to content

Instantly share code, notes, and snippets.

@cblanc
Created Jan 4, 2021
Embed
What would you like to do?
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