PDA

View Full Version : [OPEN] Options not used EventManager.onDocumentReady when ready state already set



aconran
20 Jun 2007, 11:40 AM
I discovered a bug today where I was trying to delay the loading of a singleton by a few seconds using the delay option of Ext.EventManager.onDocumentReady


Ext.EventManager.onDocumentReady(MySingleton.init, MySingleton, {delay: 3000});


I have a single page application and this singleton can be loaded in 2 ways. It can be loaded by refreshing the browser OR it can be loaded after logging into my application.

In the later scenario it is loaded by an UpdateManager with scripts set to true.

Ext.EventManager.onDocumentReady simply runs the function without paying any attention to the options if the doc's ready state is already set.


onDocumentReady : function(fn, scope, options){
if(docReadyState){ // if it already fired
fn.call(scope || window, scope);
return;
}


Until the real fix comes out which supports all options I am using the following code which solves my problem.


if(docReadyState){
if (options && options.delay) {
fn.defer(options.delay, scope || window);
} else {
fn.call(scope || window, scope);
}
return;
}

aconran
2 Jul 2007, 10:07 AM
Any update on this? I noticed the same problem is in 1.1 beta2.

aconran
5 Aug 2007, 5:39 AM
Jack has informed that this will be fixed in the 2.0 release.

Aaron

aconran
12 Sep 2007, 7:33 AM
I took note that this is fixed in both the 1.1.1 and 2.0 code base.

Aaron

Animal
12 Sep 2007, 1:12 PM
There's still the bug in the Ext.EventManager.onDocumentrReady function that I reported a while ago.

That is, used in the correct context (ie before the document is ready) listener functions are permanently added - ready to react to futher document ready events being fired.

So that means your original page-initializing function will get called again when some other code does an Ext.onReady while the document is ready, because the event will fire again to ensure that that new function is called immediately!

It needs



Ext.apply(options, {
single: true
});


!!!!

jack.slocum
13 Sep 2007, 5:31 AM
It already clears the listeners:

docReadyEvent.clearListeners();

Animal
13 Sep 2007, 6:03 AM
Only when a listenr is added after the document is already ready.

When used correctly, before the document is ready, the listener stays, and if onReady is used again, the event refires, and the original page initialization function will run again.

This is the code in SVN (plus my comment)



onDocumentReady : function(fn, scope, options){
if(docReadyState){ // if it already fired
docReadyEvent.addListener(fn, scope, options);
docReadyEvent.fire();
docReadyEvent.clearListeners();
return;
}
if(!docReadyEvent){
initDocReady();
}
docReadyEvent.addListener(fn, scope, options); // This listener is permanent,
// it needs {single: true}
},