Last active
February 3, 2020 00:06
-
-
Save Glutnix/0e09f6232b29fbfd92b5d6e3a13bc887 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 { 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