Skip to content

Instantly share code, notes, and snippets.

@bradstewart
Created April 28, 2021 18:34
Show Gist options
  • Save bradstewart/dd1c27b894b509c443cb6b076a456ffe to your computer and use it in GitHub Desktop.
Save bradstewart/dd1c27b894b509c443cb6b076a456ffe to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const operationMachine = Machine({
id: 'op',
initial: 'ready',
context: {
loadPoolId: '',
blockTime: '',
exampleData: 0,
},
states: {
ready: {
on: {
START: { target: 'applyingOnSite' },
},
},
applyingOnSite: {
entry: ['runOnSiteMitigator',],
on: {
NEXT: { target: 'updatingOTAs', cond: 'isOnSiteComplete' },
WAIT: { internal: true },
},
},
updatingOTAs: {
entry: ['runOTAUpdater',],
on: {
NEXT: { target: 'applyingOTAs' },
},
},
applyingOTAs: {
entry: ['runOTAMitigator'],
on: {
NEXT: [
{ target: 'done', cond: 'isOTAMitigationComplete' },
{ internal: false,
actions: [
assign({ exampleData: (context, event) => context.exampleData++ })
] },
],
WAIT: { internal: true },
},
},
done: {
type: 'final'
},
},
}, {
guards: {
hasData: (context, event) => {
return true
},
isOnSiteComplete: (context, event) => {
console.log('isOnSiteComplete!')
return true
},
isOTAMitigationComplete: (context, event) => {
console.log('isOTAMitigationComplete!', context.exampleData)
return context.exampleData > 3
}
},
actions: {
runOnSiteMitigator: (context, event) => {
console.log('runOnSiteMitigator!')
},
runOTAUpdater: (context, event) => {
console.log('runOTAUpdater!')
},
runOTAMitigator: (context, event) => {
console.log('runOTAMitigator!')
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment