On Tue, Dec 16, 2008 at 3:47 PM, Eoghan <[email protected]> wrote:
> 2. Modify the lookup by id convention to lookup by selector + map:
> connect('#my-ul li', 'onclick', func);
Yes, changing these lookups would break the current API. But it
wouldn't be impossible to create a migration path with decent
backwards compatibility if we really want to.
The more important issues with this, I think, is that we would have to:
* Change every MochiKit.DOM, Style, Signal, Visual... function that
accepts the current shortcut to work properly on node lists (not just
individual nodes).
* Add the MochiKit.Selector module as a dependency for the DOM module
(actually a circular dependency).
I'm not very convinced that this is the right direction, but on the
other side I hardly ever use the current shortcut either. My own use
cases all rely on keeping object maps with direct references to my DOM
nodes.
> 4. Map if passed an array-like
> connect($$('#my-ul li'), 'onclick', func);
This looks like the fastest way forward right now.
But instead of connecting signal handlers all over, I'd personally do
the following instead:
var func = function (evt) {
var li = evt.target();
if (li.tagName == null || li.tagName.toUpperCase() != "LI") {
li = getFirstParentByTagAndClassName(evt.target(), "LI");
}
... whatever you wanted to do ...
}
connect('my-ul', 'onclick', func);
Agreed that using getFirstParentByTagAndClassName() gets a bit messy,
since it doesn't check the specified node for a match (just the
parents).
> 5. More powerful partial:
> forEach($$('#my-ul li'), partial(connect, __, 'onclick', func));
We probably need the more powerful partial or bind, but I'm not so
sure about this API.
Cheers,
/Per
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---