Skip to content

Instantly share code, notes, and snippets.

@FeliciousX
Last active September 3, 2020 06:00
Show Gist options
  • Save FeliciousX/df09c063ab257be8914c3d49624b3ee1 to your computer and use it in GitHub Desktop.
Save FeliciousX/df09c063ab257be8914c3d49624b3ee1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'content',
context: {
itemData: null,
hoverOverItem: null
},
initial: 'idle',
states: {
idle: {
entry: 'clearContext',
on: {
DRAG: {
target: 'dragging',
actions: 'setItemData'
},
CLICK: {
target: 'addingItem',
actions: 'setItemData'
}
}
},
addingItem: {
invoke: {
id: 'addingItem',
src: 'getItem',
onDone: {
target: 'idle',
actions: 'addItem'
},
onError: {
target: 'idle',
actions: 'logError'
}
}
},
dragging: {
invoke: {
src: 'getHoverOverItem$'
},
on: {
DROP: 'addingItem',
HOVER: 'hovering',
DRAG_END: 'idle'
}
},
hovering: {
entry: 'setHoverOverItem',
on: {
DROP: 'addingItem',
DRAG_LEAVE: 'dragging'
},
after: {
SWAP_DELAY: {
target: 'swapping',
cond: 'isSameType',
actions: 'swapItem'
}
}
},
swapping: {
on: {
DRAG_LEAVE: {
target: 'dragging',
actions: 'revertSwapItem'
},
DRAG_END: 'idle'
}
}
}
}, {
delays: {
SWAP_DELAY: () => 1000
},
guards: {
isSameType: () => true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment