[whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

2013-06-28 Thread Zirak A
Currently, a DocumentFragment only inherits from Node, and thus loses methods 
like getElementById. However, the Selector API 
(http://www.w3.org/TR/selectors-api/) defines querySelector and 
querySelectorAll on document fragments.
My proposal is to add getElementById (which makes sense, as the document 
fragment is a root node), getElementsByTagName (and its namespace-sensitive 
version), getElementsByClassName and getElementsByName - in short, all of the 
general selection methods available on the Document.


Re: [whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

2013-06-28 Thread Zirak A
Because they may result in the same thing, but they have different semantic
meanings. I want to get an element by its id, not run a CSS selector. I want
to get elements by their tag names, not run a CSS selector.

Besides my personal aversion towards selectors being in the DOM API, there's
also the simple fact that it makes sense for document fragments to have these
methods.

- Original Message -
From: Tab Atkins Jr.
Sent: 06/28/13 09:06 PM
To: Zirak A
Subject: Re: [whatwg] Proposal: Adding methods like getElementById and 
getElementsByTagName to DocumentFragments
 On Fri, Jun 28, 2013 at 1:19 PM, Zirak A zi...@mail.com wrote:
 Currently, a DocumentFragment only inherits from Node, and thus loses methods 
 like getElementById. However, the Selector API 
 (http://www.w3.org/TR/selectors-api/) defines querySelector and 
 querySelectorAll on document fragments.
 My proposal is to add getElementById (which makes sense, as the document 
 fragment is a root node), getElementsByTagName (and its namespace-sensitive 
 version), getElementsByClassName and getElementsByName - in short, all of the 
 general selection methods available on the Document.

Given that you have querySelector, why would you want the other
functions? getElementById(foo) is just querySelector(#foo),
getElementsByTagName(foo) is just querySelectorAll(foo), etc.

~TJ 


Re: [whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

2013-06-28 Thread Zirak A
My intention wasn't for this to be an argument whether the selectors API make
anything before them obsolete. The intention was to make the API more
consistent - if documents have a getElementById method, so should document
fragments.
I acknowledge that selectors let you write more complex queries, and that some
developers prefer them. However, others (like me) prefer using the older
methods like getElementById. As said, this is an attempt to make the API more
consistent, given that we already have methods like getElementById.
  
- Original Message -
From: Tab Atkins Jr.
Sent: 06/28/13 10:51 PM
To: Zirak A
Subject: Re: [whatwg] Proposal: Adding methods like getElementById and 
getElementsByTagName to DocumentFragments
 On Fri, Jun 28, 2013 at 2:28 PM, Zirak A zi...@mail.com wrote:
 Because they may result in the same thing, but they have different semantic
 meanings. I want to get an element by its id, not run a CSS selector. I want
 to get elements by their tag names, not run a CSS selector.

There's no semantic difference between the methods. querySelector is
simply a more powerful querying function than the old DOM methods,
capable of doing everything the old methods did and much more.

 Besides my personal aversion towards selectors being in the DOM API, there's
 also the simple fact that it makes sense for document fragments to have these
 methods.

That's far from obvious, given that I don't think it makes sense to
spread those obsolete methods around any further.

~TJ 


Re: [whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

2013-06-28 Thread Zirak A
But that's a bit looking at it backwards. Selectors are supposed to be an
abstraction over these methods, not the other way around. The point here is that
document fragments are documents - so they should have a consistent API.
Adding this isn't about backwards compatibility or anything of the sort. It's
adding methods that people already use, because as said, not everyone uses
selectors (and not just because of browser-compat).
  
- Original Message -
From: Tab Atkins Jr.
Sent: 06/28/13 11:52 PM
To: Zirak A
Subject: Re: [whatwg] Proposal: Adding methods like getElementById and 
getElementsByTagName to DocumentFragments
 On Fri, Jun 28, 2013 at 4:45 PM, Zirak A zi...@mail.com wrote:
 My intention wasn't for this to be an argument whether the selectors API make
 anything before them obsolete. The intention was to make the API more
 consistent - if documents have a getElementById method, so should document
 fragments.
 I acknowledge that selectors let you write more complex queries, and that some
 developers prefer them. However, others (like me) prefer using the older
 methods like getElementById. As said, this is an attempt to make the API more
 consistent, given that we already have methods like getElementById.

While consistency with the past is good, it shouldn't be fetishized.
Adding methods means more code in the browsers, which is a non-zero
cost. When the requested feature is literally 100% obsoleted by
another feature that already exists, there's really no reason to add
the requested feature.

Note that you can add these yourself, if desired, by adding methods to
the DocumentFragment prototype that are defined in terms of
querySelector.

~TJ