Skip to content

Instantly share code, notes, and snippets.

@thorgas
Last active May 9, 2020 07:51
Show Gist options
  • Select an option

  • Save thorgas/9ca2e68d8d79e26fdada6e7efa79259a to your computer and use it in GitHub Desktop.

Select an option

Save thorgas/9ca2e68d8d79e26fdada6e7efa79259a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const firestoreFetchMachine = Machine({
id: "myMachine",
initial: "idle",
context: { doc: { products: "a product" } },
states: {
idle: {
on: {
INIT: "init"
}
},
init: {
invoke: {
id: "setDoc",
src: (context, event) => PromiseFunction(context.doc),
onDone: {
target: "success",
actions: (ctx, e) => console.log(e), // do stuff with your resolved Promise
},
onError: {
target: "failure",
actions: (ctx, e) => console.log(e), // do stuff with your resolved Promise
}
}
},
success: {},
failure: {}
}
}); // end of machine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment