Skip to content

Instantly share code, notes, and snippets.

@karlguillotte
Last active August 30, 2021 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlguillotte/2e336a44f6c97645e0dac8c5aea6c0c3 to your computer and use it in GitHub Desktop.
Save karlguillotte/2e336a44f6c97645e0dac8c5aea6c0c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const agreementMachine = Machine({
id: 'agreement',
initial: 'unknown',
context: {
terms: null, // Terms of use document
status: null, // 'accepted' or perhaps 'declined'
timestamp: null
},
states: {
unknown: {
on: {
'': [{
target: 'accepted',
cond: 'isAccepted'
},{
target: 'declined',
cond: 'isDeclined'
}, {
target: 'pending'
}]
}
},
pending: {
on: {
ACCEPT: {
target: 'accepted',
actions: 'accept',
},
REFUSE: {
target: 'declined',
actions: 'decline',
},
}
},
accepted: {},
declined: {
on: {
REVIEW: 'pending'
}
},
},
},{
actions: {
accept: assign({
status: 'accepted',
timestamp() {
return Date.now()
},
}),
decline: assign({
status: 'declined',
timestamp() {
return Date.now()
}
}),
},
guards: {
isAccepted(context) {
return context.status === 'accepted'
},
isDeclined(context) {
return context.status === 'declined'
}
}
})
@karlguillotte
Copy link
Author

Available variables:

  • Machine
  • interpret
  • assign
  • send
  • sendParent
  • spawn
  • raise
  • actions
  • XState (all XState exports)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment