PDA

View Full Version : multiple calls to contentPanel.setUrl()



snid
9 Feb 2007, 1:24 PM
I have a content panel that is initialized with a call to setUrl(...)

Later on, I want to change the URL that is loaded, so I call setUrl(...) again on the content panel. Now, when I activate that panel, network requests for both URLs are generated (bad), but only the content for the second one appears in that tab (good). Actually, one request finishes, the content from that is loaded, then the other request finishes and the content from that one replaces the content from the first request to finish.

Looking at the code, I see:

setUrl : function(url, params, loadOnce){
if(this.refreshDelegate){
this.removeListener('activate', this.refreshDelegate);
}
this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
this.on('activate', this._handleRefresh.createDelegate(this, [url, params, loadOnce]));
return this.el.getUpdateManager();
},

Not knowing too much about what's going on in there... is the removeListener call not finding a match because there are two calls to createDelegate, one that stores a reference in refreshDelegate, and another that actually gets set up as the on activate hander.

Would it work better as:

setUrl : function(url, params, loadOnce){
if(this.refreshDelegate){
this.removeListener('activate', this.refreshDelegate);
}
this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
this.on('activate', this.refreshDelegate);
return this.el.getUpdateManager();
},

?