Skip to content

Setup is run after "has_widgets" #127

@jokklan

Description

@jokklan

I have a setup method in almost all my widgets that sets a instance variable that should be presented by the widget. I use the after_initialize callback method to call setup. Often however do i want to pass this instance to a child widget, but the setup method is called after has_widgets so it's not set yet. Is their a way to change this order?

Example:

class UsageWidget < Apotomo:Widget
  after_initialize :setup

  has_widgets do |root|
    self << widget("usage/graph", :graph,
      usage: @usage) # doesn't work, @usage is not set yet
  end

  def display
    render
  end

  private

  def setup(widget)
    @user = options[:user]
    @organization = options[:organization]
    @usage = UsagePresenter.new(@user, @organization, view_context)
  end

end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions