Created
May 14, 2020 18:05
-
-
Save christiannwamba/d384151c29c122094a0cb5deb88ade26 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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