Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 14, 2020 18:02
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 christiannwamba/a537f1f1237f95ccf7aa1e542f49d310 to your computer and use it in GitHub Desktop.
Save christiannwamba/a537f1f1237f95ccf7aa1e542f49d310 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// DEMO: History State (Shallow)
const poweredOnStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
},
// When this state node is activated
// It returns the previous state of
// poweredOnStates
// A state that remembers :)
hist: {
type: 'history'
}
}
const spaceHeaterMachine = Machine({
id: 'spaceHeater',
initial: 'poweredOff',
states: {
poweredOff: {
on: { TOGGLE_POWER: 'poweredOn.hist' }
},
poweredOn: {
on: { TOGGLE_POWER: 'poweredOff' },
initial: 'lowHeat',
states: poweredOnStates
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment