Skip to content

Instantly share code, notes, and snippets.

@xomaczar
Created May 27, 2021 20:24
Show Gist options
  • Save xomaczar/2d9ad8e5b3b1dd2e11f23272c4bbde6c to your computer and use it in GitHub Desktop.
Save xomaczar/2d9ad8e5b3b1dd2e11f23272c4bbde6c 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 states = {
active: {
onEntry: ['handleActive'],
on: {
USER_IDLE: 'idle',
USER_ACTIVE: 'active',
TOGGLE: 'idle',
LOGOUT: 'inactive',
},
},
idle: {
onEntry: ['handleIdleChange'],
on: {
RENEW: {
target: 'active',
actions: ['handleRenew'],
cond: 'validateToken',
},
EXIT: 'inactive',
LOGOUT: {
actions: ['handleLogout'],
target: 'inactive',
},
},
},
inactive: {
actions: assign({
validToken: ({ context }) => (context.validToken = false),
}),
},
};
const aMachine = Machine({
initial: 'active',
states,
actions: {
// predefine methods to handle transitions between states
// args to expect are (context, event)
handleIdleChange() {},
handleActive() {},
handleLogout() {},
handleRenew() {},
},
guards: {
validateToken() {},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment