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

(WIP, need for a feedback!) jQuery helpers #108

Closed
wants to merge 4 commits into from
Closed

(WIP, need for a feedback!) jQuery helpers #108

wants to merge 4 commits into from

Conversation

kuraga
Copy link
Contributor

@kuraga kuraga commented Aug 9, 2013

@apotonick, need for a feedback!

WIP! Don't merge!

  • No tests
  • Docs are poor

P.S. Deeply inspired by @kristianmandrup #76

* No tests
* Docs are poor
@kristianmandrup
Copy link

Very nice!

Just looking at the Readme updates.

Why did you preface all the javascript helper functions with javascript_. That looks a bit verbose to me. Why not preface simply with js_ or jq_for the jquery specific functions?

Also, why not include a scoping block function to wrap several helper method calls?

js_helpers do |js|
  js.camelize(str)
  js.remove(id, '#top_panel')
end

In Ruby, never require a nil argument like javascript_element_action(nil, selector, action). Use introspection of the arguments instead and act accordingly or use chaining or some other more elegant pattern for a nice DSL.

javascript_element_action(id, selector, action)
javascript_element_action(selector, action)
javascript_element_action(nil, selector, action)

What is difference between the last two ? is nil an "all ids" selecor? if so, better to add method js_element_action_all or alternatively allow chaining.

jq_element_action(selector, action).by(id)
jq_element_action(selector, action).all

If they all return a String, simply subclass and extend String adding these extra chaining functions...

class Apotomo::JsElementActionString < String
  def by id
  end

  def all
  end
end

This would greatly simplify DSL, API and documentation and implementation I'm sure, furthering reuse etc :)

And so on... just some ideas and suggestions for improvement ;)

@kuraga
Copy link
Contributor Author

kuraga commented Aug 9, 2013

Kris, thanks for feedback!

Why did you preface all the javascript helper functions with javascript_. That looks a bit verbose to me. Why not preface simply with js_ or jq_ for the jquery specific functions?

Yes, 👍 because Nick used js_.

What is difference between the last two?

None. Just argument is not required or can be nil (the same). I think (maybe 😄) it's useful... Hm... See here:

def javascript_update(*args, &block)
  id, selector, markup = *extract_args(3, *args)
  javascript_element_call(id, selector, :html, Array.wrap(markup), &block)
end 

Suppose id cannot be nil. Then we should write more:

def javascript_update(*args, &block)
  id, selector, markup = *extract_args(3, *args)
  id ?
    javascript_element_call(id, selector, :html, Array.wrap(markup), &block) :
    javascript_element_call(selector, :html, Array.wrap(markup), &block)
end 

Uhm?
P.S. Don't forget - docs are absent now! It's a draft!

Also, why not include a scoping block function to wrap several helper method calls?

Yes, we (you and I) have talked about it! Sure it's the next step! After Nick's feedback...

If they all return a String, simply subclass and extend String adding these extra chaining functions...

Maybe the next... Where is a border? We shouldn't realize JS-in-Ruby language...

@kuraga kuraga closed this Aug 16, 2013
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

Successfully merging this pull request may close these issues.

2 participants