Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Last active November 30, 2019 15:00
Show Gist options
  • Save DaveHudson/f3189f9a4282b90fe8005b35b54a30a6 to your computer and use it in GitHub Desktop.
Save DaveHudson/f3189f9a4282b90fe8005b35b54a30a6 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 formMachine = Machine({
id: "form",
initial: "idle",
context: {},
states: {
idle: {
on: { FETCH: "loading" }
},
loading: {
entry: ["load"],
on: {
RESOLVE: {
target: "form",
actions: assign({
data: (context, event) => event.data
})
},
REJECT: {
target: "error",
actions: assign({
data: (context, event) => event.data
})
}
}
},
form: {
on: {
SAVE_COMPLETE: "saving",
SAVE_INCOMPLETE: "saving"
}
},
saving: {
on: {
RESOLVE: 'success',
REJECT: 'error'
}
},
success: {
type: 'final'
},
error: {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment