Permalink
Browse files

Allow multiple handlers per message on the client (#51)

  • Loading branch information...
1 parent cc3ba23 commit b1456b88565c88578d52c1825929e242e1660c42 @shimaore shimaore committed Jan 4, 2013
Showing with 7 additions and 7 deletions.
  1. +7 −7 src/client.coffee
View
@@ -9,7 +9,7 @@ skeleton = ->
context = {}
# Storage for the functions provided by the user.
- ws_handlers = {}
+ ws_handlers = []
helpers = {}
apply_helpers = (ctx) ->
@@ -36,8 +36,8 @@ skeleton = ->
helpers[k] = v
context.on = (obj) ->
- for k, v of obj
- ws_handlers[k] = v
+ for message, action of obj
+ ws_handlers.push {message,action}
context.connect = ->
context.socket = io.connect.apply io, arguments
@@ -73,9 +73,9 @@ skeleton = ->
context.share '__local', context.socket, (data) ->
context.key = data.key
- for name, h of ws_handlers
- do (name, h) ->
- context.socket.on name, (data) ->
+ for {message,action} in ws_handlers
+ do (message, action) ->
+ context.socket.on message, (data) ->
ctx =
app: app
socket: context.socket
@@ -86,7 +86,7 @@ skeleton = ->
apply_helpers ctx
- h.apply ctx
+ action.apply ctx
$(-> app.run '#/') if app?

0 comments on commit b1456b8

Please sign in to comment.