Skip to content

Instantly share code, notes, and snippets.

@rauhryan
Created October 2, 2014 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauhryan/64461d1cb0b0a2a32346 to your computer and use it in GitHub Desktop.
Save rauhryan/64461d1cb0b0a2a32346 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment