I have been a user and supporter of jQuery for a while, and I've just started a major project where we are trying to build a large interactive multimedia system without using Flash.
One problem I have run into is that there doesn't seem to be any support for isochronous events. What do I mean by this? Let me give two examples:
Let's say you are playing an animation using setInterval to generate a new event when it is time to display a new frame of the animation. But you want the animation to play in "real time" -- that is, you don't want it to slow down if your computer gets behind, or you want it to be synchronized with an audio track, or something else.
Another example is tracking mousemove events. You are receiving a stream of mousemove events to drag an object around the screen, but it takes too long to draw the object so your application is lagging behind the position of the mouse, which is disconcerting to users.
In this two examples, what you want to be able to do is throw away events, but only if there is another event already there to take its place. So instead of trying to play all the frames of an animation you might skip some frames so that the animation remains synchronized. Or you can throw away mousemove events and only redraw the object at the latest mouse position.
Unfortunately, I can't think of a simple way to implement this using jQuery's current event system (of course, I could be wrong, so if you have an idea, I'd love to hear it). But it could be simple to implement if we make a fairly minor change to the jQuery event system.
The simplest change to jQuery would be to add some way for an event handler to know if there are later events in the same event queue. So for example, in my event handler for mousemove events, I would ask if there are additional events already queued up, and if so just return (so the handler can get triggered again on the next event). To implement this, we might add a single field to the event passed into the handler, like "evt.count" which -- at the time the handler is called -- says how many events are in the event queue after this one.
A better implementation would give the event handler access to those events, so rather than just returning, it can access those events, perform some action, and then delete them from the queue. This implementation would allow more sophisticated control of isochronous events. For the example of the animation, if the animation has gotten significantly behind (say 10 frames) rather than skipping all 10 frames to catch up, the handler could start skipping every other frame until the animation catches up. To implement this, we would add a new field to the event that is passed into the handler, something like "evt.queue". We could see how many events are in the queue as "evt.queue.length" and we could remove events using "evt.queue.pop()" or "evt.queue.shift()".
There is a third way to implement this, which is possibly simpler for the user, but is less flexible. In this case, when you bind a function to an event you can specify that you only want to receive the most recent event. Something like "bindIso(type, data, fn)".
There might be other ways to provide this functionality as well, but so far my favorite would be to place a pointer to the event queue in the event passed to the handler function (the second implementation, above). This implementation allows you to deal with isochronous media is a more flexible manner.
Comments? Improvements? What's the normal way to get new features into jQuery? Should I start implementing this myself? Or, is there already some secret way to do this that I just don't know about?