Skip to content

Instantly share code, notes, and snippets.

@nandcello
Last active April 29, 2020 12:26
Show Gist options
  • Select an option

  • Save nandcello/2084672b98e8fa51f6c89c6c16fc615c to your computer and use it in GitHub Desktop.

Select an option

Save nandcello/2084672b98e8fa51f6c89c6c16fc615c 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({
initial: "idle",
context: { values: {}, error: undefined },
states: {
idle: {
on: {
SUBMIT_DETAILS: {
target: "submittingDetails",
actions: assign({
values: (_, e) => {
return { ...e.values };
},
}),
},
},
},
submittingDetails: {
invoke: {
src: "addListing",
onDone: {
target: "submissionSuccess",
},
onError: {
target: "submissionError",
actions: assign({
error: (_, e) => e.data,
}),
},
},
},
submissionSuccess: {
entry: "handleSuccess",
on: {
"": "idle",
},
},
submissionError: {
initial: "displayingNotif",
entry: "handleError",
on: {
SUBMIT_DETAILS: "submittingDetails",
},
states: {
displayingNotif: { on: { HIDE_NOTIF: "hiddenNotif" } },
hiddenNotif: {},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment