Skip to content

Instantly share code, notes, and snippets.

@garmjs
Last active July 29, 2022 17:17
Show Gist options
  • Save garmjs/2c4b23b2f6485b3f4836919e19fc792e to your computer and use it in GitHub Desktop.
Save garmjs/2c4b23b2f6485b3f4836919e19fc792e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const loginMachine = Machine({
id: "loginMachine",
initial: "idle",
context: {
loading: false,
data: null
},
states: {
idle: {
on: {
SUBMIT: {
target: "loading",
actions: assign({
loading: true
})
}
}
},
loading: {
invoke: {
id: "authentication",
src: (ctx, event) => {} // removed logic from Visualizer
},
on: {
SUCCESS: {
target: "success",
actions: assign({
loading: false,
data: (_ctx, event) => event.data
})
},
FAIL: {
target: "fail",
actions: assign({
loading: false,
data: (_ctx, event) => event.data
})
}
}
},
success: {
type: "final",
on: {
LOGOUT: {
target: "idle"
}
}
},
fail: {
on: {
CLEAR_ERROR: {
actions: assign({ data: () => null })
},
SUBMIT: {
target: "loading",
actions: assign({ loading: true })
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment