Skip to content

Instantly share code, notes, and snippets.

@FeliciousX
Last active September 18, 2020 05:48
Show Gist options
  • Save FeliciousX/a6f7e32320220a81a9b17bc4b6227208 to your computer and use it in GitHub Desktop.
Save FeliciousX/a6f7e32320220a81a9b17bc4b6227208 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
initial: 'idle',
context: {
cursorStart: {
x: 0,
y: 0
},
item: null,
siblingAbove: null,
siblingBelow: null,
transactions: []
},
states: {
idle: {
entry: 'resetContext',
on: {
dragstart: {
cond: 'isFrameLayoutParent',
target: 'dragging',
actions: 'setContext'
}
}
},
dragging: {
on: {
drag: [
{
cond: 'collideSiblingAbove',
target: 'swapping',
actions: 'swapWithSiblingAbove'
},
{
cond: 'collideSiblingBelow',
target: 'swapping',
actions: 'swapWithSiblingBelow'
}
],
dragend: {
target: 'idle'
}
}
},
swapping: {
on: {
drag: {
target: 'dragging',
actions: 'setContext'
},
dragend: 'idle'
}
}
}
}, {
guards: {
isFrameLayoutParent: () => true,
collideSiblingAbove: () => true,
collideSiblingBelow: () => true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment