Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 14, 2020 18:05
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/d384151c29c122094a0cb5deb88ade26 to your computer and use it in GitHub Desktop.
Save christiannwamba/d384151c29c122094a0cb5deb88ade26 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// DEMO: History State Deep
const heatedStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
}
}
const oscillationStates = {
enabled: {
on: {
TOGGLE_OSC: 'disabled'
}
},
disabled: {
on: {
TOGGLE_OSC: 'enabled'
}
}
}
const poweredOnStates = {
heated: {
initial: 'lowHeat',
states: heatedStates
},
oscillation: {
initial: 'disabled',
states: oscillationStates
},
hist: {
type: 'history',
//DEEP HISTORY
// When this state node is activated
// It returns the previous DEEP/NESTED (heared and oscillation) states of
// poweredOnStates
// A state that remembers :)
history: 'deep'
}
}
const spaceHeaterMachine = Machine({
id: 'spaceHeater',
initial: 'poweredOff',
states: {
poweredOff: {
on: { TOGGLE_POWER: 'poweredOn.hist' }
},
poweredOn: {
on: { TOGGLE_POWER: 'poweredOff' },
// With parallel set, you can ignore
// initial.
// This makes the poweredOn states parallel
//so they are not mutually exlusive
type: 'parallel',
states: poweredOnStates
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment