[mochikit] Weird bug in MochiKit.Style.getElementPosition

2008-12-12 Thread Per Cederberg

Hi,

I ran across a weird bug in MochiKit.Style.getElementPosition causing
FF to throw evil C++ exceptions into the console:

http://trac.mochikit.com/ticket/332

Debugging the MochiKit code I ended up looking at the following piece
of black magic:

getElementPosition: function (elem, /* optional */relativeTo) {
var self = MochiKit.Style;
var dom = MochiKit.DOM;
elem = dom.getElement(elem);

if (!elem ||
(!(elem.x  elem.y) 
(!elem.parentNode === null ||
self.getStyle(elem, 'display') == 'none'))) {
return undefined;
}

Question: What does the if-statement really do? And what was the real intention?

It seems the getStyle() function is called even though I send in a {
x: 0, y: 0 } object. I guess that is not the real intention.
Especially I like the !elem.parentNode === null check. What does
that even mean??? Weird that the previous test cases haven't caught
anything here...

Cheers,

/Per

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] connectEach shortcut

2008-12-12 Thread Eoghan

I often use the following utility function:

function connectEach(iterable, signal, dest, func){
forEach(iterable, function(el){
connect(el, signal, dest, func);
});
}

It might be used as follows:

connectEach($$('#my-ul li'), 'onclick', function(e){
// do sumn'
 });

rather than slightly more unwieldy:
forEach($$('#my-ul li'), function(el){
connect(el, 'onclick', function(e){
// do sumn'
});
 });

Is it a good candidate to include in the Signal api?

Eoghan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: connectEach shortcut

2008-12-12 Thread Arnar Birgisson

Hi

On 12.12.2008, at 16:45, Eoghan eoghanomur...@gmail.com wrote:
connectEach($$('#my-ul li'), 'onclick', function(e){
// do sumn'
 });

 rather than slightly more unwieldy:
forEach($$('#my-ul li'), function(el){
connect(el, 'onclick', function(e){
// do sumn'
});
 });

 Is it a good candidate to include in the signal api?

I can definitely see the use case, but IMO this is one of the cases  
where I'd not want to add since forEach is not that much typing. In my  
mind this the whole point of having a functional, composable API such  
as the iter module.

Just my 2000 ISK

cheers,
Arnar 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: connectEach shortcut

2008-12-12 Thread Eoghan

On Dec 12, 7:20 pm, Arnar Birgisson arna...@gmail.com wrote:
 Hi

 On 12.12.2008, at 16:45, Eoghan eoghanomur...@gmail.com wrote:

     connectEach($$('#my-ul li'), 'onclick', function(e){
                 // do sumn'
          });

  rather than slightly more unwieldy:
     forEach($$('#my-ul li'), function(el){
             connect(el, 'onclick', function(e){
                     // do sumn'
                 });
          });

  Is it a good candidate to include in the signal api?

 I can definitely see the use case, but IMO this is one of the cases  
 where I'd not want to add since forEach is not that much typing. In my  
 mind this the whole point of having a functional, composable API such  
 as the iter module.

 Just my 2000 ISK

 cheers,
 Arnar

I agree.
After consideration of generalisation, maybe what I'm looking for is a
version of `partial` that can take out of order arguments, something
along the following lines:

forEach($$('#my-ul li'), partial(connect,
MochiKit.Base.placeholder, 'onclick', function(e){
 // do sumn'
}));

Although I'm not sure what the implementation of partial would look
like in order to support out of order placeholder arguments...

Eoghan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: connectEach shortcut

2008-12-12 Thread Bob Ippolito

On Fri, Dec 12, 2008 at 11:20 AM, Arnar Birgisson arna...@gmail.com wrote:

 Hi

 On 12.12.2008, at 16:45, Eoghan eoghanomur...@gmail.com wrote:
connectEach($$('#my-ul li'), 'onclick', function(e){
// do sumn'
 });

 rather than slightly more unwieldy:
forEach($$('#my-ul li'), function(el){
connect(el, 'onclick', function(e){
// do sumn'
});
 });

 Is it a good candidate to include in the signal api?

 I can definitely see the use case, but IMO this is one of the cases
 where I'd not want to add since forEach is not that much typing. In my
 mind this the whole point of having a functional, composable API such
 as the iter module.

 Just my 2000 ISK

Personally I think it's useful, but I would rather have the connect
take a selector as a string instead of a list. Makes it much easier to
track down when the lookup happens in-connect.

connectAll(#my-ul li, onclick, ...);

(not sold on the name)

We could even have the existing API do this if passed a list, but
perhaps that's a bit too magical.

connect([#my-ul li], onclick, ...);

The other problem is that the return signature has to change for
disconnect, or we have to allow for a different kind of disconnect.

-bob

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: connectEach shortcut

2008-12-12 Thread Arnar Birgisson

Hi,

On Sat, Dec 13, 2008 at 00:45, Bob Ippolito b...@redivi.com wrote:
 connect([#my-ul li], onclick, ...);

I agree this looks a little bit too magical. Perhaps more expected
would be to allow the first argument to be a list, but in that case a
list of elements (or strings passed to getElement). The selector case
is then simply:

connect($$(#my-ul li), onclick, ...);

As for the return, this would return a list. I.e.

connect(elements, event, handler) {
if (isIterable(elements)) {
return map(function (el) {connect(el, event, handler);}, elements);
} else {
// current connect code for a single element
}
}

cheers,
Arnar

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---