Skip to content

Instantly share code, notes, and snippets.

@hnordt
Created January 29, 2020 18:27
Show Gist options
  • Save hnordt/f09cbb7f7cb4426fddfe634c391ec512 to your computer and use it in GitHub Desktop.
Save hnordt/f09cbb7f7cb4426fddfe634c391ec512 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: "resource",
context: {
params: {},
data: null,
meta: {}
},
initial: "idle",
states: {
idle: {},
fetching: {
entry: "resetData",
invoke: {
src: "fetch",
onDone: {
target: "success",
actions: ["setData", "setMeta"]
},
onError: {
target: "failure",
actions: ["setData", "setMeta"]
}
}
},
debouncing: {
after: {
500: "refetching"
}
},
refetching: {
invoke: {
src: "fetch",
onDone: {
target: "success",
actions: ["setData", "setMeta"]
},
onError: {
target: "failure",
actions: ["setData", "setMeta"]
}
}
},
success: {
entry: "notifySuccess"
},
failure: {
entry: "notifyFailure",
on: {
RETRY: "fetching"
}
}
},
on: {
FETCH: {
target: "fetching",
actions: "setParams"
},
REFETCH: {
target: "debouncing",
actions: "setParams"
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment