Last active
March 6, 2020 23:27
-
-
Save davidkpiano/b437f46bbe19c39068f86a05bb3b8286 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
Machine({ | |
initial: 'idle', | |
context: { | |
dx: 0, | |
dy: 0, | |
pointerx: 0, | |
pointery: 0 | |
}, | |
states: { | |
'idle': { | |
id: 'idle', | |
entry: assign({ | |
dx: 0, | |
dy: 0, | |
pointerx: 0, | |
pointery: 0 | |
}), | |
on: { | |
// when this event happens... | |
'mousedown': { | |
// go here... | |
target: 'dragging', | |
// and do this... | |
actions: assign({ | |
pointerx: (context, event) => event.clientX, | |
pointery: (context, event) => event.clientY | |
}) | |
} | |
} | |
}, | |
'dragging': { | |
initial: 'outside', | |
states: { | |
outside: { // dragging.outside | |
on: { | |
'mouseenter': 'inside', | |
'mouseup': { | |
target: '#idle' | |
} | |
} | |
}, | |
inside: { // dragging.inside | |
on: { | |
'mouseleave': 'outside', | |
'mouseup': { | |
target: '#dropped' | |
} | |
} | |
} | |
}, | |
on: { | |
'mousemove': { | |
internal: true, | |
actions: assign({ | |
dx: (context, event) => event.clientX - context.pointerx, | |
dy: (context, event) => event.clientY - context.pointery, | |
}) | |
} | |
} | |
}, | |
'dropped': { | |
id: 'dropped', | |
after: { | |
1000: 'idle' | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment