Skip to content

Instantly share code, notes, and snippets.

@adamscott
Last active March 16, 2021 04:08
Show Gist options
  • Save adamscott/3cd7ae902cc5c8b9f6a774c41628bad8 to your computer and use it in GitHub Desktop.
Save adamscott/3cd7ae902cc5c8b9f6a774c41628bad8 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 login = {
initial: 'loggedOut',
states: {
loggedOut: {
on: {
LOGIN: 'login'
}
},
login: {
on: {
LOGIN_SUCCESS: 'loggedIn',
LOGIN_FAILURE: 'loggedOut'
}
},
loggedIn: {
on: {
LOGOUT: 'loggedOut'
}
}
}
};
const user = {
initial: 'idle',
states: {
idle: {
on: {
LOGIN_SUCCESS: 'loading'
}
},
loading: {
on: {
USER_SUCCESS: 'pending',
LOGOUT: 'idle'
}
},
pending: {
on: {
LOGOUT: 'idle'
}
}
}
};
const clients = {
initial: 'idle',
states: {
idle: {
on: {
USER_SUCCESS: 'loading'
}
},
loading: {
on: {
CLIENTS_SUCCESS: 'pending'
}
},
pending: {}
}
};
const loginMachine = Machine({
id: 'userManagement',
type: 'parallel',
context: {
jwt: null,
user: null,
clients: []
},
states: {
login,
user,
clients
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment