Module: Porous::Component::Virtual

Included in:
Porous::Component
Defined in:
lib/porous/component/virtual.rb

Instance Method Summary collapse

Instance Method Details

#component(comp, opts = {}) ⇒ Object

Used to render nested components (no caching on server)

Raises:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/porous/component/virtual.rb', line 7

def component(comp, opts = {})
  raise Error, "Component is nil in #{self.class} class" if comp.nil?

  @__virtual_nodes__ ||= []
  comp = (comp.is_a?(Class) ? comp.new(opts[:props] || {}) : comp)
         .with_root_component(@root_component)
         .inject
  comp.init
  @__virtual_nodes__ << comp.render_virtual_dom
  self
end