(Google seems to have lost my first post, sorry if this comes up
twice...)

> I think that something like this is a good candidate for the core. There's
> so many requests and things for "how can I pause my code", etc.
>
> I can't see this being all that large in size.

It's not that small, for reasons I'll come to in a second.

> I think this makes a good first impression but the ".then" starts to
> annoy me after a while (looking at the code I can see why it's there,
> but it still "feels" superfluous <--- I don't get to use that word very
> often!)

.then and .and are totally optional and are just references to the
ChainCollector instance - you can put them anywhere you like in the
chain for legibility, or not use them at all if you prefer.

The crux of all this is that I wrote ChainCollector as a general
purpose function queueing object for use with event handlers, Ajax
callbacks and post-animation callbacks in the library I'm working on.
I just used the idea of a jquery plugin to demonstrate the syntactic
possibilities it opens up. Most of its code is inspecting the objects
you're using so it knows which method names it needs to implement. A
more tightly focussed plugin would likely be smaller and better suited
to its task.

As an example, here's something you can use it to implement (this is
not jQuery, it's based on my new lib):

$('li').on('click').setStyle({color:
'#ccc'}).and.wait(1).then._('h1').setContent('Hello!')

The on() and wait() functions both use a ChainCollector to queue the
chain up for asynchronous execution.

Reply via email to