Skip to content

Instantly share code, notes, and snippets.

@azamara
Last active February 11, 2021 03:16
Show Gist options
  • Save azamara/897d74157295869b5735b7cded0d8668 to your computer and use it in GitHub Desktop.
Save azamara/897d74157295869b5735b7cded0d8668 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 defaultMachine = {
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'red'
}
},
red: {
on: {
TIMER: 'green'
},
}
}
};
const rootMachine = {
id: 'light',
initial: 'init',
context: {
theme: 'light',
},
states: {
init: {
on: {
INIT: 'ready'
}
},
ready: {
on: {
RUN: { target: '#page' },
RESET: 'init'
},
}
}
}
const pageMachine = {
id: 'page',
type: 'parallel',
states: {
sidebar: {
initial: 'off',
states: {
on: {
on: { TOGGLE_BOLD: 'off' }
},
off: {
on: { TOGGLE_BOLD: 'on' }
}
}
},
content: {
initial: 'off',
states: {
on: {
on: { TOGGLE_UNDERLINE: 'off' }
},
off: {
on: { TOGGLE_UNDERLINE: 'on' }
}
}
},
popup: {
initial: 'off',
states: {
on: {
on: { TOGGLE_ITALICS: 'off' }
},
off: {
on: { TOGGLE_ITALICS: 'on' }
}
}
},
}
}
const appMachine = Machine({
id: 'app',
initial: 'page',
context: {
retries: 0
},
states: {
start: {
on: {
LAUNCH: 'root'
}
},
root: {
...rootMachine
},
page: {
...pageMachine
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment