8000 Discussion about router · Issue #64 · clearwater-rb/clearwater · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Discussion about router #64
Open
Open
@johnsusi

Description

@johnsusi

While developing a set of components I was surprised to see that the order of which render was called was not what I was expecting.

Here is a small example

class A
  include Clearwater::Component

  def initialize(children = [])
    @children = children
  end

  def render
    puts 'render A'
    div({id: 'A'}, @children)
  end
end

class B
  include Clearwater::Component

  def render
    puts 'render B'
    div({id: 'B'}, 'hello')
  end
end

class Layout
  include Clearwater::Component

  def render
    div({id: 0}, [
      A.new([
        div({id: 1}, [
          B.new
        ])
      ])
    ])
  end
end

Console output

render B
render A

However when I remove one nested div in Layout the order is reversed.

class Layout
  include Clearwater::Component

  def render
    div({id: 0}, [
      A.new([
        B.new
      ])
    ])
  end
end

Console output

render A
render B

Looking at https://github.com/clearwater-rb/clearwater/blob/master/opal/clearwater/component.rb#L55 it is clear why it is working this way. I see no easy fix so perhaps this is just something that needs documenting.

Or do you consider Router to be the only way to nest components properly?

I guess this is not a problem in most usecases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0