Skip to content

Instantly share code, notes, and snippets.

@mshwery
Last active January 19, 2022 16:48
Show Gist options
  • Save mshwery/86336ab729bf54f5fe7d4e5bc5e3a36f to your computer and use it in GitHub Desktop.
Save mshwery/86336ab729bf54f5fe7d4e5bc5e3a36f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const needsEmail = (context, _event) => !Boolean(context.email)
const meetsCriteria = (context, _event) => Boolean(context.email)
const widgetMachine = Machine({
id: 'widget',
initial: 'hello',
context: { email: null },
states: {
hello: {
on: {
NEXT: [
{ target: 'email_form', cond: needsEmail },
{
target: 'channels'
}
]
},
},
email_form: {
on: {
UPDATE: {
actions: assign({
email: (_, event) => 'matt@koala.live'
})
},
SUBMIT: {
target: 'channels',
cond: meetsCriteria
}
}
},
channels: {
on: {
OPEN_CALENDAR: {
target: 'calendar',
cond: meetsCriteria
},
OPEN_CHAT: {
target: 'chat',
cond: meetsCriteria
},
START_VIDEO: {
target: 'video_call',
cond: meetsCriteria
},
VIEW_RESOURCES: {
target: 'resources',
cond: meetsCriteria
},
}
},
calendar: {
on: {
BACK: 'channels'
}
},
resources: {
on: {
BACK: 'channels'
}
},
chat: {
on: {
BACK: 'channels'
}
},
video_call: {
on: {
BACK: 'channels'
},
initial: 'joining',
states: {
joining: {
on: {
JOINED: 'ready',
FAILED: 'failed'
}
},
ready: {
on: {
HANG_UP: 'ended',
}
},
failed: {
on: {
RETRY: 'joining'
}
},
ended: {
}
}
}
},
guards: {
needsEmail,
meetsCriteria
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment