Sha256: ce8d49d041320b1445ebed80d2f73715d6e8a41eca9f999a42606ec2060fad8c
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
module Glimmer module Opal class ElementProxy attr_reader :parent, :args def initialize(parent, args) @parent = parent @args = args @children = [] @parent.add_child(self) end def add_child(child) return if @children.include?(child) @children << child dom << child.dom end def redraw old_dom = @dom @dom = nil old_dom.replace dom end # Subclasses must override with their own mappings def observation_request_to_event_mapping {} end def name self.class.name.split('::').last.underscore.sub(/_proxy$/, '') end def id "#{name}-#{hash}" end # Subclasses can override with their own selector def selector "#{name}##{id}" end def handle_observation_request(keyword, &event_listener) event = observation_request_to_event_mapping[keyword][:event] event_handler = observation_request_to_event_mapping[keyword][:event_handler] event_listener = event_handler&.call(event_listener) || event_listener delegate = $document.on(event, selector, &event_listener) EventListenerProxy.new(element_proxy: self, event: event, selector: selector, delegate: delegate) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
glimmer-dsl-opal-0.0.2 | lib/glimmer/opal/element_proxy.rb |