Skip to content

Instantly share code, notes, and snippets.

@tgnm
Last active January 4, 2020 11:27
Show Gist options
  • Save tgnm/0c8890b521551e5a2335c5ef8aba2006 to your computer and use it in GitHub Desktop.
Save tgnm/0c8890b521551e5a2335c5ef8aba2006 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 rebalanceStates ={
states: {
no_assignments: {
on: {
unassigned_companies: 'assign',
orphaned_companies: 'assign'
}
},
assign: {
},
companies_assigned: {
on: {
unassigned_companies: 'assign',
orphaned_companies: 'assign',
over_limit: 'shed',
}
},
shed: {
},
}
}
const projectingStates = {
states: {
read_order_actions: {
on: {
write_projections: 'rebalance_check'
}
},
rebalance_check: {
on: {
rebalance:'#rebalancing.companies_assigned'
}
},
}
}
const projectorMachine = Machine({
id: 'projector',
initial: 'start',
context: {
assignedCompanies: 0
},
states: {
start: {
on: {
register: 'registered'
}
},
registered: {
on: {
task: 'heartbeating',
rebalance: 'rebalancing'
}
},
heartbeating: {
on: {
timeout: 'shutdown',
ok: 'heartbeating',
}
},
shutdown: {
final:true
},
rebalancing: {
id: 'rebalancing',
on: {
no_companies_assigned: 'shutdown',
companies_assigned: 'projecting'
},
...rebalanceStates
},
projecting: {
...projectingStates
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment