Skip to content

Instantly share code, notes, and snippets.

@tawanorg
Created June 9, 2020 22:15
Show Gist options
  • Save tawanorg/2f9a54941edd89a176f9b4ea9e0d2b2b to your computer and use it in GitHub Desktop.
Save tawanorg/2f9a54941edd89a176f9b4ea9e0d2b2b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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