Skip to content

Instantly share code, notes, and snippets.

@eduardoleal
Last active February 9, 2021 18:58
Show Gist options
  • Save eduardoleal/74d20caafb5bf93ea981fed73591292d to your computer and use it in GitHub Desktop.
Save eduardoleal/74d20caafb5bf93ea981fed73591292d 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 fetchMachine = Machine({
id: 'lifecycle',
initial: 'pending',
states: {
pending: {
on: {
ACTIVATE: 'active',
PURGE: 'purged',
}
},
active: {
type: 'compound',
initial: 'unknown',
// Child states
states: {
unknown: {
on: {
'': [
{ target: 'premium', cond: 'isPreemium' },
{ target: 'freemium' }
]
}
},
freemium: {
on: {
upgrade: 'premium'
}
},
premium: {}
},
on: {
FREEZE: 'frozen',
}
},
frozen: {
on: {
PARTIALLY_BLOCKS: 'partiallyBlocked',
REACTIVATE: 'active',
}
},
partiallyBlocked: {
on: {
BLOCKS: 'blocked',
REACTIVATE: 'active',
}
},
blocked: {
on: {
CANCEL: 'canceled',
REACTIVATE: 'active',
}
},
canceled: {
on: {
PURGE: 'purged',
REACTIVATE: 'active',
},
},
purged: {
type: 'final',
},
}
}, {
guards: {
isFreemium: () => false,
isPreemium: () => true,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment