Last active
August 30, 2021 07:22
-
-
Save karlguillotte/2e336a44f6c97645e0dac8c5aea6c0c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Available variables: