Module: Dommy::Js

Defined in:
lib/dommy/js/runtime.rb,
lib/dommy/js/wire_tags.rb,
lib/dommy/js/import_map.rb,
lib/dommy/js/marshaller.rb,
lib/dommy/js/host_bridge.rb,
lib/dommy/js/script_boot.rb,
lib/dommy/js/handle_table.rb,
lib/dommy/js/module_loader.rb,
lib/dommy/js/dom_interfaces.rb,
lib/dommy/js/bridge_conformance.rb,
lib/dommy/js/constructor_resolver.rb,
lib/dommy/js/custom_element_bridge.rb

Defined Under Namespace

Modules: BridgeConformance, DomInterfaces, Runtime, ScriptBoot, WireTags Classes: BridgedCustomElement, ConstructorResolver, CustomElementBridge, HandleTable, HostBridge, HostCallback, HostEventListener, HostNodeFilter, ImportMap, Marshaller, ModuleLoader, ScriptBooter

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_runtimeObject

The name of the backend build_runtime uses when none is given. Set by the first backend to register (and overridable by the host).



83
84
85
# File 'lib/dommy/js/runtime.rb', line 83

def default_runtime
  @default_runtime
end

Class Method Details

.build_runtime(name = nil, **opts) ⇒ Object

Build a runtime from the named backend (or the default), passing opts to its factory. Verifies the result conforms before handing it back.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dommy/js/runtime.rb', line 102

def build_runtime(name = nil, **opts)
  name = (name || @default_runtime)&.to_sym
  factory = @runtime_factories[name]
  unless factory
    raise ArgumentError,
      "unknown JS runtime backend #{name.inspect} " \
      "(registered: #{registered_runtimes.inspect})"
  end

  Runtime.assert_conformance!(factory.call(**opts))
end

.register_runtime(name, &factory) ⇒ Object

Register a runtime factory under name. The factory receives the keyword options passed to build_runtime and must return an object satisfying the Runtime contract. The first registration becomes the default.

Raises:

  • (ArgumentError)


88
89
90
91
92
93
94
# File 'lib/dommy/js/runtime.rb', line 88

def register_runtime(name, &factory)
  raise ArgumentError, "a factory block is required" unless factory

  @runtime_factories[name.to_sym] = factory
  @default_runtime ||= name.to_sym
  name.to_sym
end

.registered_runtimesObject



98
# File 'lib/dommy/js/runtime.rb', line 98

def registered_runtimes = @runtime_factories.keys

.runtime_registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


96
# File 'lib/dommy/js/runtime.rb', line 96

def runtime_registered?(name) = @runtime_factories.key?(name.to_sym)