Skip to content

Instantly share code, notes, and snippets.

@hnordt
Last active July 20, 2019 04:49
Show Gist options
  • Save hnordt/412ab0107b0292b87ab198fda58d2e74 to your computer and use it in GitHub Desktop.
Save hnordt/412ab0107b0292b87ab198fda58d2e74 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "approvals",
context: {
page: 0,
results: [],
selectedIds: {},
error: null
},
type: "parallel",
states: {
loadApprovals: {
initial: "idle",
states: {
idle: {
on: {
SET_PAGE: {
target: "loading",
actions: "setPage"
}
}
},
loading: {
invoke: {
src: "getResults",
onDone: {
target: "idle",
actions: "setResults"
},
onError: {
target: "failure",
actions: "setError"
}
}
},
failure: {
exit: "resetError",
on: {
RETRY: "loading",
CANCEL: {
target: "idle",
actions: "rollbackPage"
}
}
}
}
},
approveSelected: {
initial: "idle",
states: {
idle: {
on: {
SELECT_ITEM: {
actions: "selectItem"
},
APPROVE_SELECTED: "loading"
}
},
loading: {
invoke: {
src: "approveSelected",
onDone: "success",
onError: {
target: "failure",
actions: "setError"
}
}
},
success: {
on: {
DONE: "idle"
}
},
failure: {
exit: "resetError",
on: {
RETRY: "loading",
CANCEL: "idle"
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment