#7279 - .bind("ready") events fire out of order #80

Closed
wants to merge 6 commits into
from

Projects

None yet

2 participants

@cowboy
Member
cowboy commented Oct 30, 2010

My changes fix the issue described in this ticket. Here's an updated JSFiddle using my local build.

I basically check to see if the bind subsystem exists, and if it does, use rootjQuery.bind( "ready", fn ) otherwise just use readyList.push( fn ).

I also added a bunch of unit tests, so if nothing else you should grab those.

Hope this helps!

cowboy added some commits Oct 30, 2010
@cowboy cowboy Added DOM ready unit tests based on my understanding of how DOM ready…
… should work
e97a933
@cowboy cowboy DOM ready handlers bound with jQuery(document).bind( 'ready', fn ) wi…
…ll now execute (and unbind) immediately if jQuery.isReady is true
638e57f
@cowboy cowboy Binding a handler to DOM ready now utilizes the events system first, …
…if possible. This ensures that ready event handlers execute in the proper order, regardless of how they are bound. Handlers bound via jQuery(document).bind( 'ready', fn ) will still have the event object passed in, while handlers bound via jQuery( fn ) and jQuery(document).ready( fn ) will still have a reference to jQuery passed in.
14584f3
@cowboy cowboy Crockford yelled at me, so I removed an unecessary semicolon 190084e
@cowboy cowboy removed extraneous console.log 012247c
@cowboy cowboy tweaked unit tests to be a little more thorough, tweaked event logic …
…to pass in a proper jQuery event object in the case of jQuery(document).bind( 'ready', fn ) being called after DOM ready. This solution can't be as full-featured as if trigger were called, but it should work well enough until the whole DOM ready sub-structure can be re-written.
c85f13f
@cowboy
Member
cowboy commented Nov 1, 2010

BTW, I consider this a temporary fix. I really think that the DOM ready event system should really get an overhaul to avoid issues like these in the future.. but I don't know that the overall behavior (which my changes address) needs to wait until 1.5.

@dmethvin
Member

Ben, the ready code is most likely being replaced by the Deferreds implementation from jaubourg, so all of this is getting an overhaul. From the discussion in the ticket and the code it seems like the two major issues were that some handlers were firing multiple times (fixed in DOM0 already) and also that handlers fired out of the order they were attached. Anything else?

@cowboy
Member
cowboy commented Dec 26, 2010

The big issues I had were that:

  • some bound handlers were firing twice (already fixed).
  • unlike other "event shortcut" methods, $.fn.ready isn't a shortcut for $.fn.bind, which isn't a problem by itself, but these confusing side effects arise...
  • bound handlers can fire out-of-order, depending on which method is used to bind them.
  • when fn is called in $( fn ) and $(document).ready( fn ), a reference to jQuery is passed, but when fn is called in $(document).bind( "ready", fn ), an event object is passed.
@dmethvin
Member

Ben, I suspect several of these issues are already resolved in 1.5.2, but can you review and see what might be left? I'm trying to figure out if #7279 should be closed or not.

@cowboy
Member
cowboy commented Mar 31, 2011

Added a replacement pull #293, killing this one.

@cowboy cowboy closed this Mar 31, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment