Make the CallbacksRegistry a separate module, though rather small.

This commit is contained in:
Cheng Zhao 2013-05-05 20:30:38 +08:00
parent f725927c44
commit 67f998357c
4 changed files with 34 additions and 38 deletions

View file

@ -0,0 +1,21 @@
module.exports =
class CallbacksRegistry
constructor: ->
@nextId = 0
@callbacks = {}
add: (callback) ->
@callbacks[++@nextId] = callback
@nextId
get: (id) ->
@callbacks[id]
call: (id, args...) ->
@get(id).call global, args...
apply: (id, args...) ->
@get(id).apply global, args...
remove: (id) ->
delete @callbacks[id]