Class: Dommy::Js::HostEventListener

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

Overview

An event listener backed by a live JS object implementing the EventListener interface (a handleEvent method, e.g. Stimulus's action listeners). Implements #handle_event so Dommy's invoke_listener routes to the object's handleEvent (with this bound to the object). Holds the JS-side ref so it also wraps back to the same JS object (identity kept).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bridge, ref, label = nil) ⇒ HostEventListener

Returns a new instance of HostEventListener.



506
507
508
509
510
# File 'lib/dommy/js/host_bridge.rb', line 506

def initialize(bridge, ref, label = nil)
  @bridge = bridge
  @ref = ref
  @label = label
end

Instance Attribute Details

#refObject (readonly)

Returns the value of attribute ref.



504
505
506
# File 'lib/dommy/js/host_bridge.rb', line 504

def ref
  @ref
end

Instance Method Details

#handle_event(event) ⇒ Object



512
513
514
# File 'lib/dommy/js/host_bridge.rb', line 512

def handle_event(event)
  @bridge.invoke_js_ref_handle_event(@ref, event)
end