Skip to content

Instantly share code, notes, and snippets.

@Glutnix
Last active February 3, 2020 00:06
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 Glutnix/0e09f6232b29fbfd92b5d6e3a13bc887 to your computer and use it in GitHub Desktop.
Save Glutnix/0e09f6232b29fbfd92b5d6e3a13bc887 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const { log } = actions;
const fetchLuke = () =>
fetch("https://swapi.co/api/people/1/").then(response => response.json());
// Define machine externally
const toggleMachine = Machine({
id: "toggle",
initial: "inactive",
states: {
inactive: {
on: {
TOGGLE: "activating"
}
},
activating: {
entry: log("activating"),
invoke: {
id: "fetchLuke",
src: (context, event) => fetchLuke(),
onDone: {
target: "active",
actions: log((context, event) => event.data)
},
onError: {
target: "inactive"
}
}
},
active: {
on: { TOGGLE: "inactive" }
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment