Skip to content

Instantly share code, notes, and snippets.

@pkellner
Last active January 26, 2021 01:26
Show Gist options
  • Save pkellner/9eb8931558be6f43b507b87c24a9e54b to your computer and use it in GitHub Desktop.
Save pkellner/9eb8931558be6f43b507b87c24a9e54b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const svccUiMachine = Machine({
id: 'svccUiMachine1',
context: {
currentCodeCampYear: '2019',
codeCampYears: [
'2005',
'2006',
'2007',
'2008',
'2009',
'2010',
'2011',
'2012',
'2013',
'2014',
'2015',
'2016',
'2017',
'2018',
'2019',
],
},
type: 'parallel',
states: {
codeCampYear: {
on: {
previousYear: {
actions: assign({
currentCodeCampYear: (context, event) => {
// NOTE: add guard stuff
const currentIndex = context.codeCampYears.findIndex(
(year) => year === context.currentCodeCampYear,
);
return context.codeCampYears[currentIndex - 1];
},
}),
},
setYear: {
actions: assign({
currentCodeCampYear: (context, event) => {
const currentIndex = context?.codeCampYears.findIndex(
year => year === event.year,
);
return currentIndex >= 0
? context.codeCampYears[currentIndex]
: context.currentCodeCampYear;
return;
},
}),
},
},
},
authenticationStatus: {
initial: 'notAuthenticated',
states: {
notAuthenticated: {
on: { loggedIn: 'authenticated' },
},
authenticated: {
initial: 'hidingFavorites',
on: { loggingOut: 'notAuthenticated' },
states: {
showingFavorites: {
on: {
hideFavorites: 'hidingFavorites',
},
},
hidingFavorites: {
on: {
showFavorites: 'showingFavorites',
},
},
},
},
},
},
sessionsDisplayStatus: {
initial: 'hidingSessions',
states: {
showingSessions: {
on: {
hideSessions: 'hidingSessions',
},
},
hidingSessions: {
on: {
showSessions: 'showingSessions',
},
},
},
},
theme: {
initial: 'light',
states: {
light: {
on: {
setDarkTheme: 'dark',
},
},
dark: {
on: {
setLightTheme: 'light',
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment