[Prototype-core] Re: String#times performance pit in IE

2007-09-26 Thread Andrew Red

Gees, awesome!

On Sep 26, 3:09 pm, "Martin Ström" <[EMAIL PROTECTED]> wrote:
> Try benchmarking this solution as well, it doesn't even use an for
> loop which could make it even a bit faster:
>
> String.prototype.times3 = function(count) {
> return new Array(count + 1).join(this);
>
> }
>
> Hej
> Martin
>
> On 25/09/2007, Andrew Red <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
>
> > As can be noted by increasing the argument in String#times, execution
> > time slows down dramatically and makes logarithmically identical curve
> > (to one produced my String#times in FireFox), yet of doubled order
> > magnitude.
>
> > An alternative method for IE exists that makes use of array
> > concatenation. Below are the tests, benchmarks and conclusions:
>
> > Object.extend(String.prototype, {
> > times1: function(count) { // current method employed in Prototype
> > var result = '';
> > for (var i = 0; i < count; i++) result += this;
> > return result;
> > },
> > times2: function(count) { // a method that works best in IE:
> > for (var i = 0, result = []; i < count; i++) 
> > result.push(this);
> > return result.join('');
> > }
> > });
>
> > Unit tests:
> > testTimes1: function() {with(this) { /* */
> >   for (var i = 55, j = 34, k; i < 1; k = i + j, j = i, i = k) //
> > using fibonacci series to use for arguments
> >   benchmark(function() { 'foo'.times1(i); }, 100);
> > }},
>
> > testTimes2: function() {with(this) { /* */
> >   for (var i = 55, j = 34, k; i < 1; k = i + j, j = i, i = k)
> > benchmark(function() { 'foo'.times2(i); }, 100);
> > }},
>
> > Results in FF:
> > passed  testTimes1  7 assertions, 0 failures, 0 errors
> > Info: Operation finished 100 iterations in 0.015s (1)
> > Info: Operation finished 100 iterations in 0.016s (2)
> > Info: Operation finished 100 iterations in 0.031s (3)
> > Info: Operation finished 100 iterations in 0.063s (4)
> > Info: Operation finished 100 iterations in 0.078s (5)
> > Info: Operation finished 100 iterations in 0.406s (6)
> > Info: Operation finished 100 iterations in 0.406s (7)
> > Info: Operation finished 100 iterations in 0.563s (8)
> > Info: Operation finished 100 iterations in 0.922s (9)
> > Info: Operation finished 100 iterations in 1.468s (10)
> > Info: Operation finished 100 iterations in 2.266s (11)
> > passed  testTimes2  7 assertions, 0 failures, 0 errors
> > Info: Operation finished 100 iterations in 0.031s (1)
> > Info: Operation finished 100 iterations in 0.047s (2)
> > Info: Operation finished 100 iterations in 0.078s (3)
> > Info: Operation finished 100 iterations in 0.125s (4)
> > Info: Operation finished 100 iterations in 0.172s (5)
> > Info: Operation finished 100 iterations in 0.297s (6)
> > Info: Operation finished 100 iterations in 0.687s (7)
> > Info: Operation finished 100 iterations in 0.985s (8)
> > Info: Operation finished 100 iterations in 1.422s (9)
> > Info: Operation finished 100 iterations in 2.453s (10)
> > Info: Operation finished 100 iterations in 7.297s (11)
>
> > Results in IE:
> > passed testTimes1 7 assertions, 0 failures, 0 errors
> > Info: Operation finished 100 iterations in 0.031s (1)
> > Info: Operation finished 100 iterations in 0.078s (2)
> > Info: Operation finished 100 iterations in 0.141s (3)
> > Info: Operation finished 100 iterations in 0.5s (4)
> > Info: Operation finished 100 iterations in 0.875s (5)
> > Info: Operation finished 100 iterations in 1.828s (6)
> > Info: Operation finished 100 iterations in 5.281s (7) !!!
> > Info: Operation finished 100 iterations in 11.781s (8) !!!
> > Info: Operation finished 100 iterations in 29.156s (9)  !!!
> > Info: Operation finished 100 iterations in 70.813s (10) !!!
> > Info: Operation finished 100 iterations in 184.812s (11) 
> > passed testTimes2 7 assertions, 0 failures, 0 errors
> > Info: Operation finished 100 iterations in 0.047s (1)
> > Info: Operation finished 100 iterations in 0.063s (2)
> > Info: Operation finished 100 iterations in 0.078s (3)
> > Info: Operation finished 100 iterations in 0.172s (4)
> > Info: Operation finished 100 iterations in 0.234s (5)
> > Info: Operation finished 100 iterations in 0.406s (6)
> > Info: Operation finished 100 iterations in 0.719s (7)
> > Info: Operation finished 100 iterations in 1.094s (8)
> > Info: Operation finished 100 iterations in 1.859s (9) (15.9 times
> > better)
> > Info: Operation finished 100 iterations in 2.891s (10) (24.5 times
> > better)
> > Info: Operation finished 100 iterations in 4.5s  (11) (40 times
> > better!)
>
> > Can it be considered that more suiting method is used for IE?
> > Like:
> > if (Prototype.Browser.IE) {
> >   String.prototype.times = function(count) {
> > for (var i = 0, result = []; i < count; i++) result.push(this);
> > return result.join('');
> >   };
> > }
>
> > Thanks!
>
> > Best regards,
>
> >

[Prototype-core] Re: Submitted a Patch, Mark as Fixed?

2007-09-26 Thread Woil

Thanks... you're right, someone else massaged me. They accepted my
patch!

On Sep 26, 2:16 pm, jdalton <[EMAIL PROTECTED]> wrote:
> I would assumed "not fixed" until it is included in the source by the
> devs...
> I would let them dictate when they fix something.


--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Submitted a Patch, Mark as Fixed?

2007-09-26 Thread jdalton

I would assumed "not fixed" until it is included in the source by the
devs...
I would let them dictate when they fix something.


--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread Ihárosi Wiktor

Andrew Dupont wrote:
> Not being able to use the descendant combinator after a :not clause,
> however, is a bug. Wiktor, feel free to report it; I'll try to fix it
> before 1.6 final.
Thx Andrew!

Here is the ticket with the attached diff:
http://dev.rubyonrails.org/ticket/9696

--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread Andrew Dupont

The CSS2 and CSS3 specs disagree on this, annoyingly enough. [1] I'd
originally written ":not" to throw an exception on selectors with more
than one token, but then I saw the conflicting definitions and
relented. All the other major libraries seem to allow this confusing
syntax.

Not being able to use the descendant combinator after a :not clause,
however, is a bug. Wiktor, feel free to report it; I'll try to fix it
before 1.6 final.

Cheers,
Andrew


[1] http://www.w3.org/TR/REC-CSS2/selector.html#q2

On Sep 26, 10:51 am, kangax <[EMAIL PROTECTED]> wrote:
> Interesting,
>
> >From w3c specs (http://www.w3.org/TR/2001/CR-css3-selectors-2003/
>
> #negation):
> "The negation pseudo-class is a functional notation taking a simple
> selector (excluding the negation pseudo-class itself and pseudo-
> elements) as an argument."
>
> Now what is simple selector (http://www.w3.org/TR/2001/CR-css3-
> selectors-2003/#simple-selectors-dfn) ?
> "A simple selector is either a type selector, universal selector,
> attribute selector, ID selector, content selector, or pseudo-class.
> One pseudo-element may be appended to the last sequence of simple
> selectors."
>
> Looks like your 'a:not(a[rel$="nofollow"]' is not quite a simple
> selector (but rather a combination of type and attribute ones)
>
> Besides, a:not(a[rel^=external]) doesn't make sense in the first place
> (just like div:not(div) which will never match) : )
> Why select  that are not  with some condition when you could
> just specify condition on its own. It will be tested against all 
> anyway: a:not([rel^=external])
>
> Hope this helps,
> 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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: String#times performance pit in IE

2007-09-26 Thread Sam Stephenson

On Sep 26, 2007, at 6:09 AM, Martin Ström wrote:

> Try benchmarking this solution as well, it doesn't even use an for
> loop which could make it even a bit faster:
>
> String.prototype.times3 = function(count) {
>return new Array(count + 1).join(this);
> }

In general I think these endless debates over the performance of  
methods like String#times, $w, et al are unnecessary and  
counterproductive.

That said... wow!  What a beautiful and succinct way of approaching  
the problem.  I really like your thinking, Martin.

-sam
--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread Ihárosi Wiktor

kangax wrote:
> Besides, a:not(a[rel^=external]) doesn't make sense in the first place
> (just like div:not(div) which will never match) : )
> Why select  that are not  with some condition when you could
> just specify condition on its own. It will be tested against all 
> anyway: a:not([rel^=external])

Yes, I think I understand. I checked them in w3c's validator in css3 
profile and it says too they are invalid.

But as I mentioned I these selectors are not mine. :) I simply copy them 
from the original prototype unit tests and write something _after_ the 
:not(). I didn't checked contents of :not(). (My fault. :)

Thank you for correct me and as Mislav asked me, I will report it to 
Trac with a diff.


--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread kangax

Interesting,

>From w3c specs (http://www.w3.org/TR/2001/CR-css3-selectors-2003/
#negation):
"The negation pseudo-class is a functional notation taking a simple
selector (excluding the negation pseudo-class itself and pseudo-
elements) as an argument."

Now what is simple selector (http://www.w3.org/TR/2001/CR-css3-
selectors-2003/#simple-selectors-dfn) ?
"A simple selector is either a type selector, universal selector,
attribute selector, ID selector, content selector, or pseudo-class.
One pseudo-element may be appended to the last sequence of simple
selectors."

Looks like your 'a:not(a[rel$="nofollow"]' is not quite a simple
selector (but rather a combination of type and attribute ones)

Besides, a:not(a[rel^=external]) doesn't make sense in the first place
(just like div:not(div) which will never match) : )
Why select  that are not  with some condition when you could
just specify condition on its own. It will be tested against all 
anyway: a:not([rel^=external])

Hope this helps,
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: keypress remapped as keydown in prototype 1.6rc0

2007-09-26 Thread Adam McCrea
I doubt it's a coincidence that this discussion started right after this
ticket was posted:

http://dev.rubyonrails.org/ticket/9666

My main question is why 1.6 is remapping keypress for all browsers.  It used
to only do so for WebKit and IE.  As the reporter of this ticket discovered,
Firefox has issues suppressing the  key on keydown.  This seems like
a significant issue since it will cause a form submission.

On 9/25/07, Andrew Red <[EMAIL PROTECTED]> wrote:
>
>
> Will it be addressed, then?
>
> On Sep 25, 5:05 pm, "Mislav Marohnić" <[EMAIL PROTECTED]>
> wrote:
> > On 9/25/07, Viktor Kojouharov <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > Is there any particular reason why this remap has been introduced?
> >
> > Yes. In certain browsers (WebKit, for one), the keycode property isn't
> > available on that event, so it's remapped to achieve cross-browser
> > compatibility. I, for one, never realized it fires continuously while
> the
> > button is being held down.
>
>
> >
>

--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: String#times performance pit in IE

2007-09-26 Thread Martin Ström

Thanks ;)

On 26/09/2007, Tobie Langel <[EMAIL PROTECTED]> wrote:
>
> Brilliant Martin!
>
> as usual...!
>
>
> Martin Ström wrote:
> > Try benchmarking this solution as well, it doesn't even use an for
> > loop which could make it even a bit faster:
> >
> > String.prototype.times3 = function(count) {
> > return new Array(count + 1).join(this);
> > }
> >
> > Hej
> > Martin
>
>
> >
>


-- 
burnfield.com/martin

--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: String#times performance pit in IE

2007-09-26 Thread Tobie Langel

Brilliant Martin!

as usual...!


Martin Ström wrote:
> Try benchmarking this solution as well, it doesn't even use an for
> loop which could make it even a bit faster:
>
> String.prototype.times3 = function(count) {
> return new Array(count + 1).join(this);
> }
>
> Hej
> Martin


--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread Ihárosi Wiktor

kangax wrote:
> There's actually a syntax error in the failing test on that page:
> 
> a:not(a[rel$="nofollow"]) should be a:not([rel$="nofollow"]) =>
> "Selects any a element without a rel attribute that ends with
> nofollow."

Hmm, really. I didn't notice it. The selector.html in unit test contains 
this too:

assertEnumEqual([$('link_2')], $$('#p a:not([rel~=nofollow])'), 
'attribute 1');
assertEnumEqual([$('link_2')], $$('#p a:not(a[rel^=external])'), 
'attribute 2');
assertEnumEqual([$('link_2')], $$('#p a:not(a[rel$=nofollow])'), 
'attribute 3');
assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"]) > em'), 
'attribute 4')

So if I understand it well 2nd, 3rd and 4th selector shouldn't return 
nodes in the unit test because they are invalid?

--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread kangax

There's actually a syntax error in the failing test on that page:

a:not(a[rel$="nofollow"]) should be a:not([rel$="nofollow"]) =>
"Selects any a element without a rel attribute that ends with
nofollow."

See http://penguin.theopalgroup.com/cgi-bin/css3explainer/selectoracle.py
for more info


--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: :not() selector bugs

2007-09-26 Thread Mislav Marohnić
On 9/26/07, Wiktor Ihárosi <[EMAIL PROTECTED]> wrote:
>
>
> Should I create a ticket in trac?


Yeah, it would be best if you attached a diff to that ticket that adds some
failing tests to the current unit test suite for selector module.

--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: String#times performance pit in IE

2007-09-26 Thread Martin Ström

Try benchmarking this solution as well, it doesn't even use an for
loop which could make it even a bit faster:

String.prototype.times3 = function(count) {
return new Array(count + 1).join(this);
}

Hej
Martin

On 25/09/2007, Andrew Red <[EMAIL PROTECTED]> wrote:
>
> As can be noted by increasing the argument in String#times, execution
> time slows down dramatically and makes logarithmically identical curve
> (to one produced my String#times in FireFox), yet of doubled order
> magnitude.
>
> An alternative method for IE exists that makes use of array
> concatenation. Below are the tests, benchmarks and conclusions:
>
> Object.extend(String.prototype, {
> times1: function(count) { // current method employed in Prototype
> var result = '';
> for (var i = 0; i < count; i++) result += this;
> return result;
> },
> times2: function(count) { // a method that works best in IE:
> for (var i = 0, result = []; i < count; i++) 
> result.push(this);
> return result.join('');
> }
> });
>
> Unit tests:
> testTimes1: function() {with(this) { /* */
>   for (var i = 55, j = 34, k; i < 1; k = i + j, j = i, i = k) //
> using fibonacci series to use for arguments
>   benchmark(function() { 'foo'.times1(i); }, 100);
> }},
>
> testTimes2: function() {with(this) { /* */
>   for (var i = 55, j = 34, k; i < 1; k = i + j, j = i, i = k)
> benchmark(function() { 'foo'.times2(i); }, 100);
> }},
>
> Results in FF:
> passed  testTimes1  7 assertions, 0 failures, 0 errors
> Info: Operation finished 100 iterations in 0.015s (1)
> Info: Operation finished 100 iterations in 0.016s (2)
> Info: Operation finished 100 iterations in 0.031s (3)
> Info: Operation finished 100 iterations in 0.063s (4)
> Info: Operation finished 100 iterations in 0.078s (5)
> Info: Operation finished 100 iterations in 0.406s (6)
> Info: Operation finished 100 iterations in 0.406s (7)
> Info: Operation finished 100 iterations in 0.563s (8)
> Info: Operation finished 100 iterations in 0.922s (9)
> Info: Operation finished 100 iterations in 1.468s (10)
> Info: Operation finished 100 iterations in 2.266s (11)
> passed  testTimes2  7 assertions, 0 failures, 0 errors
> Info: Operation finished 100 iterations in 0.031s (1)
> Info: Operation finished 100 iterations in 0.047s (2)
> Info: Operation finished 100 iterations in 0.078s (3)
> Info: Operation finished 100 iterations in 0.125s (4)
> Info: Operation finished 100 iterations in 0.172s (5)
> Info: Operation finished 100 iterations in 0.297s (6)
> Info: Operation finished 100 iterations in 0.687s (7)
> Info: Operation finished 100 iterations in 0.985s (8)
> Info: Operation finished 100 iterations in 1.422s (9)
> Info: Operation finished 100 iterations in 2.453s (10)
> Info: Operation finished 100 iterations in 7.297s (11)
>
> Results in IE:
> passed testTimes1 7 assertions, 0 failures, 0 errors
> Info: Operation finished 100 iterations in 0.031s (1)
> Info: Operation finished 100 iterations in 0.078s (2)
> Info: Operation finished 100 iterations in 0.141s (3)
> Info: Operation finished 100 iterations in 0.5s (4)
> Info: Operation finished 100 iterations in 0.875s (5)
> Info: Operation finished 100 iterations in 1.828s (6)
> Info: Operation finished 100 iterations in 5.281s (7) !!!
> Info: Operation finished 100 iterations in 11.781s (8) !!!
> Info: Operation finished 100 iterations in 29.156s (9)  !!!
> Info: Operation finished 100 iterations in 70.813s (10) !!!
> Info: Operation finished 100 iterations in 184.812s (11) 
> passed testTimes2 7 assertions, 0 failures, 0 errors
> Info: Operation finished 100 iterations in 0.047s (1)
> Info: Operation finished 100 iterations in 0.063s (2)
> Info: Operation finished 100 iterations in 0.078s (3)
> Info: Operation finished 100 iterations in 0.172s (4)
> Info: Operation finished 100 iterations in 0.234s (5)
> Info: Operation finished 100 iterations in 0.406s (6)
> Info: Operation finished 100 iterations in 0.719s (7)
> Info: Operation finished 100 iterations in 1.094s (8)
> Info: Operation finished 100 iterations in 1.859s (9) (15.9 times
> better)
> Info: Operation finished 100 iterations in 2.891s (10) (24.5 times
> better)
> Info: Operation finished 100 iterations in 4.5s  (11) (40 times
> better!)
>
> Can it be considered that more suiting method is used for IE?
> Like:
> if (Prototype.Browser.IE) {
>   String.prototype.times = function(count) {
> for (var i = 0, result = []; i < count; i++) result.push(this);
> return result.join('');
>   };
> }
>
> Thanks!
>
>
> Best regards,
>
> Andrew Revinsky
>
>
> >
>


-- 
burnfield.com/martin

--~--~-~--~~~---~--~~
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 

[Prototype-core] :not() selector bugs

2007-09-26 Thread Wiktor Ihárosi

In my project I want to use the ':not' selector, but I think I found a
bug.

I cut down the unit test page for presenting the error. Here it is:
http://devidens.hu/prototype/20070926/

If I write something after the ':not' - I want all its descendants,
for example: 'a:not([id]) span' - it returns nothing. If I use the
child selector (>) after the ':not' it works well. But this has
another bug, if I don't write whitespace _before_ the child selector
(:not([id])>) it throws an exception. (This should be valid css
afaik.)

In the original unit test there is no ':not' selector with something
after it, either :not(foobar)> formula so the test passes.

I tried to debug, but perhaps this part is the most complicated code
in prototype so I have to give it up... :)

Should I create a ticket in trac?


--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Some observations and suggestions regarding AJAX

2007-09-26 Thread Richard Quadling

Hi.

I've been diving into the Ajax code in the core.

Some observations.

1 - Registered Ajax.Responders for onSuccess/onFailure are not called
(http://dev.rubyonrails.org/ticket/9643).

2 - Registered Ajax.Responders for onXYZ are not called.

I've got a way to deal with this, but I'm not sure if there is a "better" way.

Basically, the Ajax.Responders.dispatch() method needs to return
true/false if there was a dispatch.

==code==
  dispatch: function(callback, request, transport, json) {
var b_Return = false;
this.each(function(responder) {
  if (Object.isFunction(responder[callback])) {
try {
  responder[callback].apply(responder, [request, transport, json]);
  b_Return = true;
} catch (e) { }
  }
});
  return b_Return;
  }
==code==

So, now in Ajax.Request.prototype.respondToReadyState() method
includes this mod (extends the patch I've supplied) ...

==code==
if(!Ajax.Responders.dispatch('on' + response.status, this, response,
response.headerJSON)) {
  Ajax.Responders.dispatch('on' + (this.success() ? 'Success' :
'Failure'), this, response, response.headerJSON);
}
==code==

This matches the behaviour of the non responder callbacks (the ones
supplied to the request in the options collection).

3 - Exceptions.

It seems that the parameters to the onException callback only includes
the Ajax.Request object. If you are trying to examine the data
returned (say a JSON object supplied in a header as X-JSON, which is
visible in the Ajax.Response), you can't.

Every response has a reference to the request, but not the other way around.

==code==
Ajax.Response.prototype = {
  initialize: function(request){
this.request = request;
==code==

Is there any complication in adding ...

==code==
this.request.response = this;
==code==

This attaches the response to the request which is then passed to the
exception handler and now you can get to the json in the header. Phew!



I hope this is understandable.

Regards,

Richard Quadling.



-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

--~--~-~--~~~---~--~~
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 this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---