class Sirens::Component

Public Class Methods

new(props = Hash[]) click to toggle source

Initializes this component

Calls superclass method Sirens::AbstractComponent::new
# File lib/components/component.rb, line 9
def initialize(props = Hash[])
    super(props)

    build
end

Public Instance Methods

build() click to toggle source

Configures the widget with its model, styles and child widgets but does not apply the styles yet. This method is called when opening a widget with ::open and after calling ::initialize_handles. The building of the widget includes defining its model, its style props and its event blocks, but does no apply those styles yet. The wiring and synchronization of the component to the widget is done in the ::post_build method.

# File lib/components/component.rb, line 26
def build()
    set_model( props.key?(:model) ? props[:model] : default_model )

    render_with(LayoutBuilder.new(root_component: self))

    self
end
create_view() click to toggle source
# File lib/components/component.rb, line 15
def create_view()
    ComponentView.new
end
main_child_component() click to toggle source

Accessing

# File lib/components/component.rb, line 37
def main_child_component()
    @child_components.first
end
on_component_added(child_component) click to toggle source

Adds the child_component to this component.

# File lib/components/component.rb, line 53
def on_component_added(child_component)
    @view.add_view(child_component.view)
end
open() click to toggle source
# File lib/components/component.rb, line 57
def open()
    main_child_component.open
end
render_with(layout) click to toggle source

Hook method to allow each Component subclass to define its default styles and compose its child components. Subclasses are expected to implement this method.

# File lib/components/component.rb, line 46
def render_with(layout)
    raise RuntimeError.new("Class #{self.class.name} must implement a ::render_with(layout) method.")
end