Skip to content

Instantly share code, notes, and snippets.

@lozandier
Last active February 7, 2020 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lozandier/d73a0db226e0b0ce63a04cdd79d342e3 to your computer and use it in GitHub Desktop.
Save lozandier/d73a0db226e0b0ce63a04cdd79d342e3 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: 'ImpactApp',
initial: 'initializing',
context: {
version: 1,
view: 'projects',
projects: new Map([[1, {id: 1}], [2, {id: 2}]]),
currentProject: {id: 1}
},
states: {
initializing: {
on: {
APP_DATA_INITIALIZED: {
target: 'initialized',
cond: 'validAppDataLoaded'
}
},
},
initialized: {
initial: 'online',
states: {
// The dialog bit is for demonstration purposes only; you likely want views to be a state machine in & of itself
online: {
initial: 'normal',
on: {
NETWORK_OFFLINE: 'offline',
},
states: {
normal: {
// This would normally be a parallel state
on: {
OPEN_PROJECTS_DIALOG: {
target: 'projects_dialog_opened',
cond: 'validProjectIsSelected'
}
}
},
projects_dialog_opened: {
on: {
CLOSE_PROJECTS_DIALOG: 'normal'
}
}
}
},
offline: {
on: {
NETWORK_ONLINE: 'online'
}
}
},
on: {
RESET_APP: {
target: 'initializing',
}
},
}
},
}, {
guards: {
validAppDataLoaded: context => !!Number.isSafeInteger(context.version),
validProjectIsSelected: context => ( !!context.currentProject && !!context.projects && context.view == 'projects' && context.projects.has(context.currentProject.id) )
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment