Skip to content

Setup is run after "has_widgets" #127

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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