2013-05-05 12:30:38 +00:00
|
|
|
module.exports =
|
|
|
|
class CallbacksRegistry
|
|
|
|
constructor: ->
|
2013-12-06 07:04:51 +00:00
|
|
|
@emptyFunc = -> throw new Error "Browser trying to call a non-exist callback
|
|
|
|
in renderer, this usually happens when renderer code forgot to release
|
|
|
|
a callback installed on objects in browser when renderer was going to be
|
|
|
|
unloaded or released."
|
2013-05-05 12:30:38 +00:00
|
|
|
@callbacks = {}
|
|
|
|
|
|
|
|
add: (callback) ->
|
2013-12-06 07:04:51 +00:00
|
|
|
id = Math.random().toString()
|
|
|
|
@callbacks[id] = callback
|
|
|
|
id
|
2013-05-05 12:30:38 +00:00
|
|
|
|
|
|
|
get: (id) ->
|
2013-12-06 07:04:51 +00:00
|
|
|
@callbacks[id] ? ->
|
2013-05-05 12:30:38 +00:00
|
|
|
|
|
|
|
call: (id, args...) ->
|
|
|
|
@get(id).call global, args...
|
|
|
|
|
|
|
|
apply: (id, args...) ->
|
|
|
|
@get(id).apply global, args...
|
|
|
|
|
|
|
|
remove: (id) ->
|
|
|
|
delete @callbacks[id]
|