Skip to content

Instantly share code, notes, and snippets.

@TylerBarnes
Last active February 28, 2020 09:13
Show Gist options
  • Select an option

  • Save TylerBarnes/c9c116de59c8088a8d434831c20c7950 to your computer and use it in GitHub Desktop.

Select an option

Save TylerBarnes/c9c116de59c8088a8d434831c20c7950 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const inGatsbyDir = {
initial: "unsureIfPluginIsInstalled",
states: {
unsureIfPluginIsInstalled: {
onEntry: "determineIfSourcePluginIsInstalled",
on: {
SOURCE_PLUGIN_IS_INSTALLED: "sourcePluginIsInstalled",
SOURCE_PLUGIN_IS_NOT_INSTALLED: "sourcePluginIsNotInstalled",
},
},
sourcePluginIsInstalled: {
onEntry: "determineIfPluginIsConfigured",
initial: "unsureIfPluginIsConfigured",
states: {
unsureIfPluginIsConfigured: {
onEntry: "determineIfSourcePluginIsConfigured",
on: {
SOURCE_PLUGIN_IS_CONFIGURED: "sourcePluginIsConfigured",
SOURCE_PLUGIN_IS_NOT_CONFIGURED: "sourcePluginIsNotConfigured",
},
},
sourcePluginIsConfigured: {
onEntry: "determineIfWPInstanceIsConfigured",
},
sourcePluginIsNotConfigured: {
initial: "unsureIfWeShouldConfigureSourcePlugin",
states: {
unsureIfWeShouldConfigureSourcePlugin: {
onEntry: "askIfWeShouldConfigureTheSourcePlugin",
on: {
CONFIGURE: "configuringPlugin",
EXIT: "#cli.exit",
},
},
configuringPlugin: {},
},
},
},
},
sourcePluginIsNotInstalled: {
on: {
INSTALL_PLUGIN: "sourcePluginIsNotInstalled.installingPlugin",
EXIT: "#cli.exit",
},
initial: "unsureIfWeShouldInstall",
states: {
unsureIfWeShouldInstall: {
onEntry: "askIfWeShouldInstallSourcePlugin",
on: {
INSTALL: "installingPlugin",
EXIT: "#cli.exit",
},
},
installingPlugin: {
onEntry: "installSourcePlugin",
on: {
PLUGIN_INSTALLED: "#cli.inGatsbyDir.sourcePluginIsInstalled",
},
},
},
},
},
}
const cliMachine = Machine({
id: "cli",
initial: "started",
states: {
started: {
on: {
IS_GATSBY: "inGatsbyDir",
ISNT_GATSBY: "inUnknownDir",
},
onEntry: "checkIfIsGatsbyDir",
},
inGatsbyDir,
inUnknownDir: {
initial: "notSureIfWeShouldCreateAGatsbySite",
states: {
notSureIfWeShouldCreateAGatsbySite: {
onEntry: "askIfWeShouldCreateAGatsbySite",
on: {
CREATE: "creatingGatsbySite",
EXIT: "#cli.exit",
},
},
creatingGatsbySite: {
initial: "siteNotYetCreated",
onEntry: "createNewGatsbySite",
on: {
GATSBY_SITE_CREATED: "creatingGatsbySite.siteCreated",
},
states: {
siteNotYetCreated: {
onEntry: "createNewGatsbySite",
on: {
SITE_CREATED: "siteCreated",
},
},
siteCreated: {
onEntry: "cdToNewGatsbySite",
on: {
CHANGED_DIR: "#cli.started",
},
},
},
},
},
},
exit: {
onEntry: "exitCli",
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment