Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
catmando opened this issue Jan 6, 2016 · 3 comments
Open

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

catmando opened this issue Jan 6, 2016 · 3 comments

Comments

@catmando
Copy link
Collaborator

catmando commented Jan 6, 2016

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
Copy link
Collaborator

ajjahn commented Jan 8, 2016

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

@catmando
Copy link
Collaborator Author

catmando commented Jan 8, 2016

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
Copy link

This issue was moved to ruby-hyperloop/hyper-react#114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants