Skip to content

Instantly share code, notes, and snippets.

@dikyarga
Created December 18, 2020 01:58
Show Gist options
  • Save dikyarga/b2c78fdc5a5c8dc208541daa0f433ad1 to your computer and use it in GitHub Desktop.
Save dikyarga/b2c78fdc5a5c8dc208541daa0f433ad1 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 fetchMachine = Machine({
id: "productSearch",
initial: "idle",
context: {
products: []
},
states: {
idle: {
on: { SEARCH: "searching" }
},
searching: {
invoke: {
src: () => {},
onDone: {
target: "idle",
actions: assign({ products: (_, event) => event.data.data })
},
onError: {
target: "failed"
}
},
on: { SUCCESS: "idle", FAIL: "failed" }
},
failed: {
on: {
SEARCH: "searching"
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment