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

Element[n] throws TypeError #47

Closed
wmnnd opened this issue Sep 3, 2014 · 5 comments
Closed

Element[n] throws TypeError #47

wmnnd opened this issue Sep 3, 2014 · 5 comments

Comments

@wmnnd
Copy link
Contributor

wmnnd commented Sep 3, 2014

I expected the equivalent of JQuery's .eq(n) to be #[n] in opal-jquery.
However, only .at(n) seems to work at the moment and #[n] throws a TypeError:

require "opal-jquery"
Element.find("body").append(Element.parse("<a>test 1</a><a test 2</a>"))
elements = Element.find("a")
puts elements.length
puts elements.at(0) # <= works fine
puts elements[0] # <= "TypeError: n.toLowerCase is not a function"

For your convenience, the code on opalrb.org/try: http://ur1.ca/i454e

@wmnnd
Copy link
Contributor Author

wmnnd commented Sep 3, 2014

I see, the reason for this is that #[key] gives you access to an element's attributes. Could there be a better way to avoid the inconsistencies between Array-like behavior with #at and Hash-like behavior with #[]?

@elia
Copy link
Member

elia commented Sep 3, 2014

I remember it has been discussed. iirc we picked the 80% case (which is attr) and made array access more explicit (#at) or available after conversion with #to_a

@wmnnd
Copy link
Contributor Author

wmnnd commented Sep 3, 2014

Okay, that makes sense. Then the problem that remains is that there is no documentation on this. The Github readme links to http://opalrb.org/jquery but that page doesn't exist.
Are there currently any plans for improving the documentation of opal-jquery? Is there a way to help out?

@elia
Copy link
Member

elia commented Sep 3, 2014

Sure! Recently I started publishing opal side API docs (http://opalrb.org/docs/api/). Currently there's just core and stdlib but my plan is to publish there docs for all opal libs (a la rdoc.info)

You can grab the rails task from opal-master. Let me know if you need anything, some help is really appreciated :)

@elia
Copy link
Member

elia commented Sep 6, 2014

Closing, I'll be glad to merge PRs improving api documentation, that would be enough (I'll deal with generating yardocs myself)

@elia elia closed this as completed Sep 6, 2014
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

2 participants