react.rb icon indicating copy to clipboard operation
react.rb copied to clipboard

components should accept any number of params to be merged

Open catmando opened this issue 9 years ago • 3 comments

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

catmando avatar Jan 06 '16 23:01 catmando

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

ajjahn avatar Jan 08 '16 15:01 ajjahn

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.

catmando avatar Jan 08 '16 21:01 catmando

This issue was moved to reactrb/reactrb#114

sollycatprint avatar Jun 13 '16 13:06 sollycatprint