Class: Dommy::Js::HostCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/js/host_bridge.rb

Overview

An event listener backed by a live JS function. Implements only the bridge ABI (js_call) — not #call/#handle_event — so Dommy's invoke_listener routes through the js_call("call", [event]) branch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bridge, id) ⇒ HostCallback

Returns a new instance of HostCallback.



473
474
475
476
# File 'lib/dommy/js/host_bridge.rb', line 473

def initialize(bridge, id)
  @bridge = bridge
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



471
472
473
# File 'lib/dommy/js/host_bridge.rb', line 471

def id
  @id
end

Instance Method Details

#__js_call__(method, args) ⇒ Object



478
479
480
481
482
# File 'lib/dommy/js/host_bridge.rb', line 478

def __js_call__(method, args)
  return nil unless method == "call"

  @bridge.invoke_callback(@id, args)
end

#__js_call_with_raise__(args) ⇒ Object

Invoke and re-raise a thrown value instead of swallowing it — for a NodeFilter, whose exception must propagate out of the traversal method.



493
494
495
# File 'lib/dommy/js/host_bridge.rb', line 493

def __js_call_with_raise__(args)
  @bridge.invoke_callback(@id, args, raising: true)
end

#__js_call_with_this__(args, this_arg) ⇒ Object

Invoke with an explicit this receiver — e.g. a MutationObserver callback whose this must be the observer, or an event listener whose this is the currentTarget.



487
488
489
# File 'lib/dommy/js/host_bridge.rb', line 487

def __js_call_with_this__(args, this_arg)
  @bridge.invoke_callback(@id, args, this_arg)
end