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.
134 135 136 137 138 |
# File 'lib/dommy/bridge.rb', line 134 def initialize(host, callback_id) @host = host @callback_id = callback_id @props = {} end |
Instance Method Details
#__js_call__(method, args) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/dommy/bridge.rb', line 153 def __js_call__(method, args) case method when "call" @host.invoke_callback(@callback_id, args) end end |
#__js_get__(key) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/dommy/bridge.rb', line 140 def __js_get__(key) if key == ID_KEY @props.fetch(key, @callback_id) else @props[key] end end |
#__js_set__(key, value) ⇒ Object
148 149 150 151 |
# File 'lib/dommy/bridge.rb', line 148 def __js_set__(key, value) @props[key] = value nil end |