Last active
May 24, 2020 14:35
-
-
Save gsong/99951fdf5f58e9e56d6b09457964d90c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
const context = { useLoadingStatus: false }; | |
const queryMachine = Machine( | |
{ | |
id: "query", | |
context, | |
on: { | |
UPDATE: [ | |
{ target: "loading", cond: "isLoading" }, | |
{ target: "notFound", cond: "isNotFound" }, | |
{ target: "error", cond: "isError" }, | |
{ target: "success", cond: "isSuccess" }, | |
], | |
}, | |
initial: "loading", | |
states: { | |
error: {}, | |
loading: {}, | |
notFound: {}, | |
success: {}, | |
}, | |
}, | |
{ | |
guards: { | |
isError: (_, { queryInfo: { status } }) => status === "error", | |
isLoading: ( | |
{ useLoadingStatus }, | |
{ queryInfo: { status, isFetching } }, | |
) => (useLoadingStatus ? status === "loading" : isFetching), | |
isNotFound: (_, { queryInfo: { error } }) => | |
error?.response?.status === 404, | |
isSuccess: (_, { queryInfo: { status, data } }) => | |
status === "success" && !isEmpty(data), | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment