Permalink
Browse files

support multiple ready/close handlers

  • Loading branch information...
1 parent 00b0a3e commit f1cfcce4d272c5da8b30919dcfddb867f6c9a8f6 @contra contra committed Apr 27, 2012
Showing with 162 additions and 65 deletions.
  1. +11 −6 client/vein.coffee
  2. +74 −28 examples/chat/vein.js
  3. +2 −2 package.json
  4. +74 −28 vein.js
  5. +1 −1 vein.min.js
View
@@ -38,7 +38,10 @@ class Vein
@socket.onclose = @handleClose
return
- callbacks: {}
+ callbacks:
+ ready:[]
+ close:[]
+
subscribe: {}
getSession: => cookies.getItem @options.sessionName
@@ -50,11 +53,14 @@ class Vein
cookies.removeItem @options.sessionName
return
- ready: (cb) -> @callbacks['ready'] = cb
- close: (cb) -> @callbacks['close'] = cb
+ ready: (cb) -> @callbacks['ready'].push cb
+ close: (cb) -> @callbacks['close'].push cb
# Event handlers
- handleClose: => @callbacks['close']?()
+ handleReady: =>
+ cb() for cb in @callbacks['ready']
+ handleClose: =>
+ cb() for cb in @callbacks['close']
handleMessage: (e) =>
{id, method, params, err} = JSON.parse e.data
@@ -69,8 +75,7 @@ class Vein
handleMethods: (methods...) =>
@[method] = @getSender method for method in methods
@subscribe[method] = @getListener method for method in methods
- @callbacks['ready']? methods
- delete @callbacks['ready']
+ @handleReady methods
return
# Utilities
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,15 +1,15 @@
{
"name":"vein",
"description":"WebSocket RPC and PubSub",
- "version":"0.0.9",
+ "version":"0.0.10",
"homepage":"http://github.com/wearefractal/vein",
"repository":"git://github.com/wearefractal/vein.git",
"author":"Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"main":"./index.js",
"dependencies":{
"coffee-script":"*",
- "sockjs":"*"
+ "sockjs":"~0.3"
},
"engines":{
"node":">= 0.4.0"
Oops, something went wrong.

0 comments on commit f1cfcce

Please sign in to comment.