Created
October 2, 2014 03:32
-
-
Save rauhryan/64461d1cb0b0a2a32346 to your computer and use it in GitHub Desktop.
BaconJS example
This file contains 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
combinedBuffer = Bacon.fromBinder (sink) -> | |
freeBuffer = Bacon.fromBinder (buff) -> | |
cyto.on 'free', 'node', (e) -> | |
buff({type: 'free', node: e, position: x: e.cyTarget.position().x, y: e.cyTarget.position().y}) | |
return () -> | |
grabBuffer = Bacon.fromBinder (buff) -> | |
cyto.on 'grab', 'node', (e) -> | |
buff({type: 'grab', node: e, position: x: e.cyTarget.position().x, y: e.cyTarget.position().y}) | |
return () -> | |
Bacon.combineAsArray(grabBuffer, freeBuffer) | |
.filter (value) -> | |
ev1 = value[0] | |
ev2 = value[1] | |
if ev1.node.cyTarget.data("guid") == ev2.node.cyTarget.data("guid") | |
return ev1.position.x != ev2.position.x && ev1.position.y != ev2.position.y | |
return true; | |
.map (evs) -> | |
return evs[1].node | |
.onValue (events) -> | |
sink(events) | |
return () -> | |
combinedBuffer.bufferWithTime(300).onValue (nodeEvents) => | |
@get('stream').apply (styleChanges)=> | |
for e in nodeEvents | |
node = e.cyTarget | |
styleChanges.set "nodes.#{node.data("guid")}", position: node.position() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment