Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Last active March 27, 2020 23:57
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/344aa76fa08959506ea180a7ac429517 to your computer and use it in GitHub Desktop.
Save kyleshevlin/344aa76fa08959506ea180a7ac429517 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const itemMachine = Machine(
{
id: "item",
context: {
view: "SIDE",
},
on: {
SELECT_ALL: "forSelection.selected",
SET_VIEW: {
target: ["forHover.idle", "forSelection.unselected"],
actions: ["setView"],
},
SET_VIEW_FULL: {
target: ["forHover.idle", "forSelection.unselected"],
actions: ["setViewFull"],
},
SET_VIEW_SIDE: {
target: ["forHover.idle", "forSelection.unselected"],
actions: ["setViewSide"],
},
UNSELECT_ALL: "forSelection.unselected",
},
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",
},
},
},
},
},
},
{
actions: {
setView: assign((ctx, evt) => ({
view: evt.view,
})),
setViewFull: assign({view: 'FULL'}),
setViewSide: assign({view: 'SIDE' })
},
guards: {
isFullView: (ctx) => ctx.view === "FULL",
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment