Skip to content

Instantly share code, notes, and snippets.

@dikyarga
Created May 30, 2021 15:49
Show Gist options
  • Save dikyarga/2c23f7d6a1ea6bde23cb44731023f5bb to your computer and use it in GitHub Desktop.
Save dikyarga/2c23f7d6a1ea6bde23cb44731023f5bb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const IDLE = "idle";
const RSVP_STATES = {
SUBMITTING: "submitting",
COMING: "coming",
DECLINED: "declined",
IDLE,
CHOOSING_COMPANION: "choosingCompanion",
GUEST_PROFILE: "guestProfile",
};
const onSubmit = {
SUBMIT: RSVP_STATES.SUBMITTING,
};
const onDecline = {
DECLINE: RSVP_STATES.DECLINED,
};
const toIdle = {
IDLE,
};
const rsvpMachine = Machine({
id: "rsvp",
initial: IDLE,
states: {
idle: {
on: {
...onSubmit,
COME: RSVP_STATES.COMING,
...onDecline,
},
},
coming: {
on: {
...onSubmit,
...onDecline,
...toIdle,
CHOOSE_COMPANION: RSVP_STATES.CHOOSING_COMPANION,
},
},
choosingCompanion: {
on: {
...toIdle,
GUEST_PROFILING: RSVP_STATES.GUEST_PROFILE,
},
},
[RSVP_STATES.GUEST_PROFILE]: {
on: {
...toIdle,
...onSubmit,
},
},
declined: {
on: {
...onSubmit,
...toIdle,
COME: "coming",
},
},
submitting: {
on: {
SUBMITTED: "done",
FAILED: "error",
},
},
done: {},
error: {
on: {
DISMISS: IDLE,
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment