Skip to content

Instantly share code, notes, and snippets.

@bowheart
Created February 23, 2022 16:05
Show Gist options
  • Save bowheart/437421f52d6667f5c2362949d4c368c4 to your computer and use it in GitHub Desktop.
Save bowheart/437421f52d6667f5c2362949d4c368c4 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 isAggressor = (context, event) => {}
const isNotAggressor = (context, event) => {}
const proposalMachine = Machine({
id: 'proposal',
initial: 'waiting',
states: {
waiting: {
on: {
STATUS_NEGOTIATING: 'negotiating'
}
},
negotiating: {
on: {
STATUS_CONFIRMING: [
{
target: 'aggressorConfirming',
cond: isAggressor
},
{
target: 'nonAggressorConfirming',
cond: isNotAggressor
}
]
}
},
aggressorConfirming: {
on: {
AGGRESSOR_CHANGE: 'nonAggressorConfirming',
STATUS_NEGOTIATING: 'negotiating',
STATUS_TRADED: 'traded'
}
},
nonAggressorConfirming: {
on: {
AGGRESSOR_CHANGE: 'aggressorConfirming',
RETURN_TO_NEGOTIATION: 'confirmingAndNegotiating',
STATUS_NEGOTIATING: 'negotiating',
STATUS_TRADED: 'traded'
}
},
confirmingAndNegotiating: {
on: {
AGGRESSOR_CHANGE: 'aggressorConfirming',
RETURN_TO_LAST_LOOK: 'nonAggressorConfirming',
STATUS_NEGOTIATING: 'negotiating'
}
},
traded: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment