Module: Ruwi::Dom::DestroyDom
- Defined in:
- lib/ruwi/runtime/dom/destroy_dom.rb
Class Method Summary collapse
- .execute(vdom) ⇒ Object
- .remove_component_node(vdom) ⇒ void
- .remove_element_node(vdom) ⇒ void
- .remove_fragment_nodes(vdom) ⇒ void
- .remove_text_node(vdom) ⇒ void
Class Method Details
.execute(vdom) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruwi/runtime/dom/destroy_dom.rb', line 5 def execute(vdom) case vdom.type when Ruwi::Vdom::DOM_TYPES[:TEXT] remove_text_node(vdom) when Ruwi::Vdom::DOM_TYPES[:ELEMENT] remove_element_node(vdom) when Ruwi::Vdom::DOM_TYPES[:FRAGMENT] remove_fragment_nodes(vdom) when Ruwi::Vdom::DOM_TYPES[:COMPONENT] remove_component_node(vdom) else raise "Can't destroy DOM of type: #{vdom.type}" end vdom.el = nil end |
.remove_component_node(vdom) ⇒ void
This method returns an undefined value.
57 58 59 60 |
# File 'lib/ruwi/runtime/dom/destroy_dom.rb', line 57 def self.remove_component_node(vdom) vdom.component.unmount Ruwi::Dom::Scheduler.enqueue_job(-> { vdom.component.on_unmounted }) end |
.remove_element_node(vdom) ⇒ void
This method returns an undefined value.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruwi/runtime/dom/destroy_dom.rb', line 34 def self.remove_element_node(vdom) el = vdom.el children = vdom.children listeners = vdom.listeners el&.remove children&.each { |child| execute(child) } if listeners Events.remove_event_listeners(listeners, el) vdom.listeners = nil end end |
.remove_fragment_nodes(vdom) ⇒ void
This method returns an undefined value.
50 51 52 53 |
# File 'lib/ruwi/runtime/dom/destroy_dom.rb', line 50 def self.remove_fragment_nodes(vdom) children = vdom.children children&.each { |child| execute(child) } end |
.remove_text_node(vdom) ⇒ void
This method returns an undefined value.
28 29 30 |
# File 'lib/ruwi/runtime/dom/destroy_dom.rb', line 28 def self.remove_text_node(vdom) vdom.el&.remove end |