BaconJS example
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()