Created
May 19, 2020 03:15
-
-
Save UberMouse/aee4834675e9bec256916a470d5d90d2 to your computer and use it in GitHub Desktop.
This file contains 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
type Events = | |
| { type: "LOG_IN" } | |
| { type: "LOG_OUT" } | |
| { type: "CHECK_TOKEN_VALID" } | |
| { type: "CHECK_TOKEN_INVALID" } | |
| { type: "AUTHORIZE_OK" } | |
| { type: "AUTHORIZE_DENIED" }; | |
const machine = createMachine<{}, Events>({ | |
id: "main-auth-spec", | |
initial: "checkToken", | |
states: { | |
checkToken: { | |
on: { | |
CHECK_TOKEN_VALID: "loggedIn", | |
CHECK_TOKEN_INVALID: "loggedOut", | |
}, | |
}, | |
loggedOut: { | |
on: { | |
LOG_IN: "loggingIn", | |
}, | |
meta: { | |
test: () => {}, | |
}, | |
}, | |
loggingIn: { | |
on: { | |
AUTHORIZE_OK: "loggedIn", | |
AUTHORIZE_DENIED: "loggedOut", | |
}, | |
meta: { | |
test: () => {}, | |
}, | |
}, | |
loggedIn: { | |
on: { | |
LOG_OUT: "loggedOut", | |
}, | |
meta: { | |
test: () => {}, | |
}, | |
}, | |
}, | |
}); | |
const testModel = createModel<typeof testMachine>(machine).withEvents({ | |
LOG_IN: { | |
exec: (service) => { | |
service.send({ type: "LOG_IN" }); | |
}, | |
}, | |
LOG_OUT: { | |
exec: (service) => { | |
service.send({ type: "LOG_OUT" }); | |
}, | |
}, | |
CHECK_TOKEN_VALID: { | |
exec: () => void 0, | |
}, | |
CHECK_TOKEN_INVALID: { | |
exec: () => void 0, | |
}, | |
AUTHORIZE_OK: { | |
exec: async () => await timeout(), | |
}, | |
AUTHORIZE_DENIED: { | |
exec: () => void 0, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment