Skip to content

Instantly share code, notes, and snippets.

@larrybotha
Last active September 20, 2019 21:32
Show Gist options
  • Save larrybotha/15c143d743a94880f8e30dbce3794a46 to your computer and use it in GitHub Desktop.
Save larrybotha/15c143d743a94880f8e30dbce3794a46 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const xeroOrgMachine = Machine({
id: 'xeroOrg',
initial: 'noOrg',
states: {
noOrg: {
invoke: {
src: "requestAuthUrl",
onDone: "exchangingToken",
onError: "error.requestAuthUrl",
},
},
exchangingToken: {
invoke: {
src: "exchangeToken",
onDone: "orgFound",
onError: [
{
cond: "noAssociatedOrg",
target: "gettingOrgs",
},
{
target: "error.tokenExchange"
},
],
},
},
gettingOrgs: {
invoke: {
src: "getOrgs",
onDone: "selectOrg",
onError: "error.getOrgs",
},
},
selectOrg: {
on: {
ORG_SELECTED: {
target: "exchangingToken"
},
CREATE_ORG: {
target: "creatingOrg",
}
}
},
creatingOrg: {
invoke: {
src: "createOrg",
onDone: "exchangingToken",
onError: "error.createOrg"
}
},
error: {
states: {
tokenExchange: {
on: {
RETRY: {
target: "#xeroOrg.exchangingToken",
},
},
},
createOrg: {
on: {
RETRY: {
target: "#xeroOrg.creatingOrg"
},
},
},
getOrgs: {
on: {
RETRY: {
target: "#xeroOrg.gettingOrgs"
},
},
},
requestAuthUrl: {
on: {
RETRY: {
target: "#xeroOrg.noOrg"
}
}
},
},
},
orgFound: {
type: "final",
},
}
}, {
guards: {
noAssociatedOrg: () => Math.random() > .5
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment