Class: Dommy::Js::CustomElements

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

Overview

Bridges JS-defined custom elements to Dommy’s custom element pipeline. ‘customElements.define(name, JSClass)` on the JS side calls in here, which registers a Dommy::HTMLElement subclass for `name` whose lifecycle reactions (connected/disconnected/adopted/attributeChanged) route back to the JS instance through the bridge. The JS class’s constructor itself runs on the JS side via the construction-stack upgrade in host_runtime.js.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bridge) ⇒ CustomElements

Returns a new instance of CustomElements.



14
15
16
17
# File 'lib/dommy/js/custom_elements.rb', line 14

def initialize(bridge)
  @bridge = bridge
  @window = nil
end

Instance Attribute Details

#window=(value) ⇒ Object (writeonly)

Sets the attribute window

Parameters:

  • value

    the value to set the attribute window to.



12
13
14
# File 'lib/dommy/js/custom_elements.rb', line 12

def window=(value)
  @window = value
end

Instance Method Details

#define(name, observed) ⇒ Object



19
20
21
22
23
24
# File 'lib/dommy/js/custom_elements.rb', line 19

def define(name, observed)
  return unless @window.respond_to?(:custom_elements)

  @window.custom_elements.define(name, build_class(name, observed))
  nil
end

#upgrade(root) ⇒ Object

customElements.upgrade(root): delegate to Dommy’s registry so a subtree attached without firing reactions gets its registered elements upgraded.



28
29
30
31
32
33
# File 'lib/dommy/js/custom_elements.rb', line 28

def upgrade(root)
  return unless @window.respond_to?(:custom_elements)

  @window.custom_elements.upgrade(root)
  nil
end