Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created April 7, 2020 18:09
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 kyleshevlin/bcdabf85791e47127e507c7cf3f34fce to your computer and use it in GitHub Desktop.
Save kyleshevlin/bcdabf85791e47127e507c7cf3f34fce to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const VIEWS = {
FULL: 'FULL',
SIDE: 'SIDE'
}
const itemMachine = Machine({
id: 'item',
context: {
view: VIEWS.SIDE,
},
on: {
SELECT_ALL: 'forSelection.selected',
UNSELECT_ALL: 'forSelection.unselected',
SET_VIEW: {
target: ['forHover.idle', 'forSelection.unselected'],
actions: ['setView'],
},
},
type: 'parallel',
states: {
forHover: {
initial: 'idle',
states: {
idle: {
on: {
HOVER: 'hovered',
},
},
hovered: {
entry: ['hoverItem', 'updateAssetSelection'],
exit: ['leaveItem', 'resetAssetSelection'],
initial: 'normal',
states: {
normal: {
on: {
PRESELECT: {
target: 'preselected',
cond: 'isFullView',
},
},
},
preselected: {
on: {
LEAVE: 'normal',
},
},
},
on: {
LEAVE: 'idle',
},
},
},
},
forSelection: {
initial: 'unselected',
states: {
unselected: {
on: {
SELECT: 'selected',
},
},
selected: {
on: {
UNSELECT: 'unselected',
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment