Class: Dommy::Bridge::Callback
- Inherits:
-
Object
- Object
- Dommy::Bridge::Callback
- Defined in:
- lib/dommy/bridge.rb
Overview
Wraps an external callback handle (registered in a host-side callback table) so the JS bridge can resolve / invoke it. The external host that creates these is responsible for honoring ‘invoke_callback(callback_id, args)`.
The ‘callback_id` key on this object exposes the integer id to JS-side code that needs to round-trip it (e.g. for release / introspection).
Constant Summary collapse
- ID_KEY =
"__callback_id__"
Instance Method Summary collapse
- #__js_call__(method, args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #__js_set__(key, value) ⇒ Object
-
#initialize(host, callback_id) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(host, callback_id) ⇒ Callback
Returns a new instance of Callback.
32 33 34 35 36 |
# File 'lib/dommy/bridge.rb', line 32 def initialize(host, callback_id) @host = host @callback_id = callback_id @props = {} end |
Instance Method Details
#__js_call__(method, args) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/dommy/bridge.rb', line 51 def __js_call__(method, args) case method when "call" @host.invoke_callback(@callback_id, args) end end |
#__js_get__(key) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/dommy/bridge.rb', line 38 def __js_get__(key) if key == ID_KEY @props.fetch(key, @callback_id) else @props[key] end end |
#__js_set__(key, value) ⇒ Object
46 47 48 49 |
# File 'lib/dommy/bridge.rb', line 46 def __js_set__(key, value) @props[key] = value nil end |