Created
June 9, 2020 22:15
-
-
Save tawanorg/2f9a54941edd89a176f9b4ea9e0d2b2b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
const invokeFakeResolvedAuthApi = () => { | |
return Promise.reject("tim"); | |
}; | |
const authServerMachine = Machine({ | |
id: "server", | |
initial: "waitingForCode", | |
context: { | |
user: null | |
}, | |
states: { | |
waitingForCode: { | |
invoke: { | |
id: "auth-api", | |
src: invokeFakeResolvedAuthApi, | |
onDone: { | |
actions: assign({ user: (context, event) => event.data }) | |
}, | |
}, | |
on: { | |
entry: (ctx) => console.log('ctx', ctx), | |
CODE: { | |
actions: sendParent( | |
context => | |
({ | |
type: "TOKEN", | |
input: context | |
}) | |
, { delay: 1000 }) | |
} | |
} | |
}, | |
} | |
}); | |
const authClientMachine = Machine({ | |
id: "client", | |
initial: "idle", | |
states: { | |
idle: { | |
on: { AUTH: "authorizing" } | |
}, | |
authorizing: { | |
invoke: { | |
id: "auth-server", | |
src: authServerMachine, | |
}, | |
entry: send("CODE", { to: "auth-server" }), | |
on: { | |
TOKEN: "authorized" | |
} | |
}, | |
authorized: { | |
entry: [(ctx, e) => console.log('xx', ctx, e)], | |
type: "final" | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment