Skip to content

Instantly share code, notes, and snippets.

@VonD
Last active December 3, 2019 13:35
Show Gist options
  • Save VonD/30f1c7029ba3483c609d172cbc42515a to your computer and use it in GitHub Desktop.
Save VonD/30f1c7029ba3483c609d172cbc42515a 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 fetchMachine = Machine({
id: 'pro-app-mobile',
initial: 'loading',
states: {
loading: {
on: {
PRESENCE_STATUS_CHANGED: {
target: 'offline',
cond: 'isOffline'
},
AUTH_STATUS_CHANGED: [
{
target: 'signedOut',
cond: 'isSignedOut'
},
{
target: 'calendar'
}
]
}
},
offline: {
on: {
PRESENCE_STATUS_CHANGED: {
target: 'loading',
cond: 'isOnline'
},
}
},
signedOut: {
on: {
AUTH_STATUS_CHANGED: 'calendar'
}
},
calendar: {
on: {
AUTH_STATUS_CHANGED: 'signedOut',
ADD_APPOINTMENT: 'appointment',
EDIT_APPOINTMENT: 'appointment',
DAYS_SETTING_CHANGE: 'calendar'
},
initial: 'loading',
states: {
loading: {
on: {
DATA_HAS_CHANGED: 'idle'
}
},
idle: {
on: {
DATA_HAS_CHANGED: 'idle',
DATE_CHANGE: 'loading',
CALENDAR_CHANGE: 'loading',
REQUEST_CALENDAR_CHANGE: 'choosingCalendar',
LONG_PRESS: 'appointmentCreationTooltip'
}
},
appointmentCreationTooltip: {
on: {
DATA_HAS_CHANGED: 'appointmentCreationTooltip',
DISMISS: 'idle',
LONG_PRESS_RELEASE: '#pro-app-mobile.appointment'
}
},
choosingCalendar: {
on: {
DISMISS: 'idle',
CALENDAR_CHANGE: 'loading'
}
}
}
},
appointment: {
on: {
AUTH_STATUS_CHANGED: 'signedOut',
DISMISS: 'calendar',
},
initial: 'loadingAppointment',
states: {
loadingAppointment: {
invoke: 'loadAppointment',
onDone: 'idle',
onError: '#pro-app-mobile.calendar'
},
idle: {
on: {
CUSTOMER_CHOICE_INTENT: 'customerChoice',
CUSTOMER_UPDATE_INTENT: 'customerEditTypeChoice',
SUBMIT: 'submittingAppointment'
}
},
customerChoice: {
on: {
DISMISS: 'idle',
CUSTOMER_CHOICE: 'idle',
CUSTOMER_CREATION_INTENT: 'customer'
}
},
customerEditTypeChoice: {
DISMISS: 'idle',
CUSTOMER_EDITION_INTENT: 'customer',
CUSTOMER_CHOICE_INTENT: 'customerChoice'
},
customer: {
DISMISS: 'idle',
SUBMIT: 'idle'
},
submittingAppointment: {
invoke: 'submitAppointment',
onDone: '#pro-app-mobile.calendar',
onError: 'idle'
},
}
}
}
}, {
guards: {
isOffline: (context, event) => event.isOffline,
isOnline: (context, event) => true,
isSignedOut: (context, event) => false
},
services: {
loadAppointment: (context, event) => Promise.resolve(),
submitAppointment: (context, event) => Promise.resolve()
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment