Last active
March 16, 2021 04:08
-
-
Save adamscott/3cd7ae902cc5c8b9f6a774c41628bad8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// 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