Make the CallbacksRegistry a separate module, though rather small.
This commit is contained in:
parent
f725927c44
commit
67f998357c
4 changed files with 34 additions and 38 deletions
21
common/api/lib/callbacks_registry.coffee
Normal file
21
common/api/lib/callbacks_registry.coffee
Normal 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]
|
Loading…
Add table
Add a link
Reference in a new issue