Skip to content

Instantly share code, notes, and snippets.

@rschwabco
Created January 29, 2021 02:14
Show Gist options
  • Save rschwabco/ec67f380f985fc8c124e57f8a78b56b1 to your computer and use it in GitHub Desktop.
Save rschwabco/ec67f380f985fc8c124e57f8a78b56b1 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 fetchMachine = Machine({
initial: 'loading',
states: {
ready: {
id: "ready",
type: 'final'
},
loading: {
entry: assign({
isLoading: true,
}),
invoke: {
id: "fetch-vessel-form",
src: "getVesselForm",
onDone: {
target: "vesselFormLoaded"
},
onError: {
target: "failure",
},
},
},
vesselFormLoaded: {
initial: "idle",
on: {
SUBMIT: {
target: ".submitVesselForm"
},
},
states: {
idle: {
type: "final"
},
submitVesselForm: {
invoke: "submit-vessel-form",
src: "submitVesselForm",
onDone: {
target: "#ready"
},
onError: {
target: "failure"
}
}
}
},
failure: {
type: 'final'
}
}
},{
services: {
getVesselForm: (context, event) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
formData: {
test: true,
},
});
}, 2000);
});
},
submitVesselForm: (context, event) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
formSubmitted: {
test: true,
},
});
}, 2000);
});
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment