Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Last active December 2, 2019 16:43
Show Gist options
  • Save DaveHudson/a34289029270a32b142fedd4e114e34a to your computer and use it in GitHub Desktop.
Save DaveHudson/a34289029270a32b142fedd4e114e34a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const formMachine = Machine({
id: 'form',
initial: 'idle',
context: {},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: {
target: "loaded",
actions: assign({
data: (context, event) => event.data
})
},
REJECT: {
target: "errorapi",
actions: assign({
data: (context, event) => event.data
})
},
}
},
loaded: {
on: {
SAVE_UNFINISHED: 'saving',
SAVE_CONTINUE: 'validating'
}
},
validating: {
on: {
INVALID: 'errorvalidation',
VALID: 'saving',
}
},
errorvalidation: {
on: {
SAVE_UNFINISHED: 'saving',
SAVE_CONTINUE: 'validating'
}
},
saving: {
on: {
RESOLVE: {
target: "saved",
actions: assign({
data: (context, event) => event.data
})
},
REJECT: {
target: "errorapi",
actions: assign({
data: (context, event) => event.data
})
},
}
},
saved: {
type: 'final'
},
errorapi: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment