Skip to content

Instantly share code, notes, and snippets.

@mouselangelo
Last active May 17, 2020 12:29
Show Gist options
  • Save mouselangelo/947ffaef2372d5a5df019d93a5be380d to your computer and use it in GitHub Desktop.
Save mouselangelo/947ffaef2372d5a5df019d93a5be380d 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 maschine = Machine({
key: "subscription",
initial: "free",
context: { provider: undefined },
states: {
free: {
on: { START: "subscribed" },
},
expired: {
initial: "churned",
states: {
churned: {
on: {
RESTART: "#subscription.subscribed",
WIN_BACK: "#subscription.subscribed",
},
},
inBillingRetry: {
on: {
RECOVER: "#subscription.subscribed",
RESTART: "#subscription.subscribed",
WIN_BACK: "#subscription.subscribed",
FAILED_TO_RECOVER: "churned",
},
},
},
},
subscribed: {
initial: "autoRenewing",
states: {
autoRenewing: {
on: {
RENEW: "autoRenewing",
CANCEL: "expiring",
REFUND: "#subscription.expired",
BILLING_ERROR: "inGracePeriod",
},
},
expiring: {
on: {
EXPIRE: "#subscription.expired",
RETAIN: "autoRenewing",
RESTART: "autoRenewing",
},
},
inGracePeriod: {
on: {
RECOVER: "autoRenewing",
GRACE_PERIOD_END: "#subscription.expired.inBillingRetry",
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment