-
Notifications
You must be signed in to change notification settings - Fork 546
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
Clarify documentation on this.on(selector, ...) #265
Comments
+1 I made the same assumption. It might be a good idea to also show how to use relative selectors:
OR
It should be noted somewhere that in the first case, event handlers are attached directly to elements matching the selector, and are not delegated to the current node like they would be if one passes an object as the second argument
|
I think the docs are quite clear on this though. The signature clearly shows that the first arg is optional, can be any DOM node, and defaults to the root node. The first example shows an event being bound to |
@necolas Hmm...I really don't agree. First, there hasn't been any confusion around whether the first arg is optional or whether one is able to send any DOM node, or that the default is The confusion is where you pass a string. Nowhere in the docs does it say that this selector is relative to My recommendation would be to, under "selector: String | Element | Element collection", include |
I'm not sure I agree either. I certainly made this mistake when I first started using Flight. It's easy to assume this behaviour, so some additional clarity around the actual behaviour would make sense. |
If you read @patricknixon's comment, you'll see why I mentioned those other things. I can't see why you'd assume that the selector is relative to |
To say "I can't see why you'd assume" rather than "I'm not sure I I shouldn't have to defend why I felt confused. That implies some stupidity On 23 July 2014 18:30, Nicolas Gallagher [email protected] wrote:
|
OK. Going to reopen. Please improve this part of the docs as you see fit. |
Thanks @tbrd for your comment and @necolas for reopening. Regarding your question @necolas - about why I (and others) assume that it was relative to Another reason is that the signature VERY much looks looks like jQuery's |
The jQuery's Often times event delegation is really what you want to do. Personally I've never bound to @staeke is right when he says that a component shouldn't be able to query the DOM like that, and maybe it would be nice to allow it to select only a subset of it eg. window, document, html, head, body, link, meta, script etc. but that's OT |
Yeah I know what you mean. I think we only use that feature to bind to the |
The more I use flight, the more I see the value in binding to the document. I agree binding to anything between the node and the document (or body) feels a bit icky - but I don't see the point in being overly prescriptive. |
If you use |
@angus-c This definitely seems like the recommended approach. The downside I see with that though is that internal selectors are overrideable by outside users of your component. You might want to lock those down to prevent that, or avoid the risk of having naming conflicts with other mixins. |
@staeke can you clarify what you mean by "outside users of your component"?. Since attrs are declared/assigned defaults within the component, they can only be overriden by either an |
@angus-c sure...guess I was a little unclear. I was primarily thinking of code that calls |
I think this conversation is getting off topic. The basic thing is, it On 24 July 2014 18:54, Staffan Eketorp [email protected] wrote:
|
Pull request to fix this gladly accepted! @staeke |
Leaving this open but marking for 2.0.0 milestone, which will include a documentation revamp. |
Currently the documentation for this.on reads
I've made the mistake to believe that the selector (if it's a string) is interpreted as relative to this.$node. Please make it clear that it's a global selector.
The text was updated successfully, but these errors were encountered: