This made me think about lazy initialization of NodeListWrapper's. The
two options seem to be:
1) store an array of pure elements and turn them into wrappers on
the fly
2) turn elements into wrappers when instantiating `NodeListWrapper`
and then return these (already prepared) wrappers.
On Aug 22, 7:14 am, T.J. Crowder [EMAIL PROTECTED] wrote:
This made me think about lazy initialization of NodeListWrapper's. The
two options seem to be:
1) store an array of pure elements and turn them into wrappers on
the fly
2) turn elements into wrappers when instantiating
NodeLists are live, though, aren't
they?http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-..
Of course, but our selector implementation turns them into an array.
Ah, okay, sorry about that. I was thinking live. I've read
On Aug 22, 9:09 am, T.J. Crowder [EMAIL PROTECTED] wrote:
NodeLists are live, though, aren't
they?http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-..
Of course, but our selector implementation turns them into an array.
Ah, okay, sorry about that. I was
On Aug 22, 10:33 am, John-David Dalton [EMAIL PROTECTED]
wrote:
T.J. $$W and $$ are the same thing (just named $$W so that we know we
are talking about the new implementation).
I kind of like the idea of lazy wrapping.
That would speed up the initial selector while offering a one time hit
When iterating over a `source` items, we don't know if an item is a
wrapper or an element.
My _each implementation deals with that case pretty efficiently. The
ongoing runtime cost of item() and _each() is pretty much one extra
comparison.
Before we can do benchmarks, we should ask people
On Aug 22, 11:30 am, T.J. Crowder [EMAIL PROTECTED] wrote:
I'm not sure if we should pre-wrap elements or do the lazy init.
First approach hits the memory consumption, while second - run-time
performance. We'll need benchmarks for this.
Yeah. I know you were initially thinking pre-wrap,
@JDD: Sorry, missed your note in the melee.
T.J. $$W and $$ are the same thing (just named $$W so that we know we
are talking about the new implementation).
Depending on how $$W is implemented, I may pretty strongly want
Prototype's excellent selectors but without automatic element
wrapping.
@Ken:
Of course an argument /against/ lazy wrapping is that we would have to
make this.raw a private property because you wouldn't know if it
contains wrapped or unwrapped elements.
Yeah, that was my primary reason for keeping it separate; originally I
was thinking integrated as well but I'm
Hey folks,
Weighing in briefly (being hammered at work and at home, and not in
that fun way). Great stuff so far! Thoughts/opinions/questions:
1. IMHO, $$() should _always_ return a list/array/whatever, even if
there's only one element; it should never return the NodeWrapper
itself. Two
On Aug 21, 7:13 am, T.J. Crowder [EMAIL PROTECTED] wrote:
Hey folks,
Weighing in briefly (being hammered at work and at home, and not in
that fun way). Great stuff so far! Thoughts/opinions/questions:
1. IMHO, $$() should _always_ return a list/array/whatever, even if
there's only one
@T. J. Crowder take some time to look at the jQuery source, it might
help with the wrapper discussion.
I was not suggesting that $$() return a list in some cases and a
single item in others. I was saying that
getter/setter methods would execute on the first matched item.
In jQuery (jQuery
On Aug 21, 9:21 am, T.J. Crowder [EMAIL PROTECTED] wrote:
Hiya,
2. FWIW, it seems to me that calling an accessor on a list should
return a list of the accessor results for each list element. Always.
...
This is tricky : )
On one hand, having accessor act on all elements seems
@JDD:
Thanks. I understood your suggsetion about the accessors, I thought
I'd also (separately) seen a suggestion that $$() return a single
wrapped element when it only finds one, but I'm not immediately
finding what it was that made me thing that. Sounds like we're all on
the same page wrt
I like the wrapper tack (same way Ext does it). .raw doesn't sound intuitive
to me though. Why not just use .dom for the underlying element (also like
Ext)? Or .el? .raw just doesn't make for a beautiful API, IMHO :)
And no, don't make it a function call.
On Thu, Aug 21, 2008 at 10:41 AM, T.J.
I disagree on the list applying accessors to only the first element.
From an API perspective I just don't see that it makes sense. I'd
much rather see a first() method or property, or better yet (as I
suggested to kangax) an explicit means of saying give me the first
(and only the first)
This happens anytime one needs to reference an element without id:
$$('[name='+prop+']')[0]; // get element by name
$$('tbody tr:first-child')[0]; // get first row of a table
$$('img[src^=data:image]')[0]; // get image with specified src
attribute
Sure, that makes much more sense to me
On Aug 21, 10:44 am, John-David Dalton [EMAIL PROTECTED]
wrote:
@T. J. Crowder take some time to look at the jQuery source, it might
help with the wrapper discussion.
I was not suggesting that $$() return a list in some cases and a
single item in others. I was saying that
getter/setter
// if source is a method
$$(css).source() - equiv
$$(css)[0].source() - equiv
$$(css).first().source() - equiv
you could always cache it
var source = $$(css).source();
// an array of sources
$$(css).invoke('source'); // OR
$$(css).each($$.source); //notice static $$.source method
kangax wrote:
...
Ken,
I wanted to keep $W consistent with the rest of the library - be a
simple shortcut for creating a new instance of NodeWrapper. Just like `
$H` returns `new Hash` and $R returns `new ObjectRange`, $W should
probably return `new NodeWrapper`. $W is also responsible for
Kangax looks good.
I think that it should be $() instead of $W(), but for the purpose of
clarity during the
discussion the use of $W is fine.
I think that any method that returned element, will instead return
NodeWrapper.
Any method that returned an array of elements will return a
On Aug 20, 10:13 am, John-David Dalton [EMAIL PROTECTED]
wrote:
Kangax looks good.
I think that it should be $() instead of $W(), but for the purpose of
clarity during the
discussion the use of $W is fine.
I think that any method that returned element, will instead return
NodeWrapper.
Any
I like where all this is heading -- thumbs up, Kangax.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from
kangax wrote:
...
If the node list returns 1 element then methods like $$
(...).getValue() should return the value of that element.
(this is how jQuery handles it)
This could lead to ambiguity. We should probably discuss it more.
I agree that it is ambiguous. I find the selector result
@Key Snyder - correct I was assuming Array.prototype was not extended
and that we were using wrappers.
@kangax
I don't think there would be confusion with things like $$
(..).getValue() here.
Keep in mind users do use the equiv of $$('#myId') and that in those
cases you are expecting 1 result
...
I forked prototype, and started working on NodeWrapper/NodeListWrapper
- http://github.com/kangax/prototype/tree/master/src/element.js
Accompanying tests are there as well (although the test suite is far
from being complete).
--
kangax
Exciting to see in code! What about adding caching
On Aug 21, 12:15 am, Ken Snyder [EMAIL PROTECTED] wrote:
... I forked prototype, and started working on NodeWrapper/NodeListWrapper
-http://github.com/kangax/prototype/tree/master/src/element.js
Accompanying tests are there as well (although the test suite is far
from being complete).
On Aug 20, 12:02 am, Walter Lee Davis [EMAIL PROTECTED] wrote:
On Aug 19, 2008, at 11:46 PM, kangax wrote:
$W('foo').wrap('div', { className: 'bar' }); // NodeWrapper around a
newly created `div` element with class=bar
Sorry to barge in the middle here, but could you clarify what 'foo'
28 matches
Mail list logo