zetachang / react.rb

Opal Ruby wrapper of React.js library.
http://reactrb.org/
MIT License
547 stars 35 forks source link

components should accept any number of params to be merged #114

Open catmando opened 8 years ago

catmando commented 8 years ago

for example

  div(attributes, {more: :stuff}, :big, id: "hello", style: {display: :none})

should be the same as

  div(attributes.merge {more: :stuff, big: true, id: "hello, style: {display: none})

Why? because sometimes you have a ready made set of params (i.e. attributes passed to a component) and you want to merge in others.

this is how you process the attributes (i just wanted to make sure it would work)

  args.inject({}) do |h, item|
    if item.is_a? Hash 
      h.merge item
    else
      h[item] = true
      h
    end
  end
ajjahn commented 8 years ago

@catmando Can you provide a more complete example, so I can be sure I'm following the motivation for this?

catmando commented 8 years ago

From our code base. This is the actual example that trigged this issue

          def render
              div do
                button(params.attributes.merge({id: "#{job.finishing.id}_trigger_button"})) do  
           #   fixing this would allow us to write: 
           #   button(params.attributes, id: "#{job.finishing.id}_trigger_button")
                  "Advanced Options"
                end.on(:click) do
                  Element["#finishing_options_modal"].modal('show')
                end
                dialog_box
              end if has_advanced_options?
          end

once you allow the first parameter to be a hash to be merged with the rest, you might as well generalize and allow any combination of hashes, and strings.

sollycatprint commented 8 years ago

This issue was moved to reactrb/reactrb#114