opal / opal-browser

Browser support for Opal.
MIT License
115 stars 36 forks source link

Browser::DOM::NodeSet missing #each method ? #40

Closed balmoral closed 9 years ago

balmoral commented 9 years ago

Browser::DOM::NodeSet calls #each in many places but #each is not implemented.

Also, in Browser::DOM::Node#<<(node) the argument is checked to see whether it responds to #each, which if a NodeSet it should but doesn't.

This test code was failing for me at c << headers:

  def index_ready # in a Volt controller
    c = container
    c << headers
    c.append_to($document.body)
  end

   def container
      DOM {
        div(class: 'container', id: 'container1')
      }
    end

    def headers
      DOM {
        div.h1.style(color: 'blue') {
          "Heading 1"
        }
        div.h2.style(color: 'red')  {
          "Heading2"
        }
      }
    end

The following patch to NodeSet fixed the problem:

class NodeSet
  ...
  def each(&block)
    @literal.each do |e|
      yield e
    end
end
meh commented 9 years ago

NodeSet#each comes from NodeSet#method_missing, the actual bug was that NodeSet#respond_to_missing? wasn't implemented.

It's now implemented on master, so it should work, reopen the issue if it's not the case.

balmoral commented 9 years ago

Works now. Thanks for fast fix.

meh commented 9 years ago

You were lucky, I just got out of bed because I couldn't sleep :panda_face:

balmoral commented 9 years ago

You've built some pretty amazing tools here. Do hope you get some well-deserved rest. :smile: