PDA

View Full Version : suspending/resuming events in Ext.History



dfrye
3 Nov 2010, 8:55 PM
I'm trying to add a new token to Ext.History without firing the History's "change" event.
When I add an event to Ext.History like so


Ext.History.add('mytoken');

the "change" event in Ext.History gets fired. Makes sense. So I tried this:


Ext.History.suspendEvents();
Ext.History.add('mytoken');

This works. The "change" event does not fire. But of course I don't want to turn event firing off permanently. I thought I could turn it back on like this:


Ext.History.suspendEvents();
Ext.History.add('mytoken');
Ext.History.resumeEvents();

But this, unfortunately, does not work. "Change" fires when I add the new token, just like in the original, single line of code up above. Am I doing something wrong here?

Condor
3 Nov 2010, 11:58 PM
The token is updated asynchronously, so you are calling resumeEvents before the token has actually changed.

It's really ugly, but you would have to use:

Ext.History.suspendEvents();
Ext.History.add('mytoken');
var task = Ext.TaskMgr.start({
run: function(){
if (Ext.History.getToken() == 'mytoken') {
Ext.TaskMgr.stop(task)
Ext.History.resumeEvents();
}
},
interval: 50
});

(which is why I recommend using a flag in your change handler instead)

steffenk
4 Nov 2010, 2:52 AM
i also made a workaround


e3.setHistory = function(title) {
e3.App.historySet = true;
document.title = e3.siteTitle + ': ' + title;
var token = e3.App.singleUid + e3.tokenDelimiter + e3.App.category
+ e3.tokenDelimiter + e3.App.subCategory + e3.tokenDelimiter
+ e3.App.media + e3.tokenDelimiter + e3.App.blog;
Ext.History.add(token);
(function() {
e3.App.historySet = false;
}).defer(150);

};

where i cancel the history onChange handler when e3.App.historySet is true

dfrye
4 Nov 2010, 1:31 PM
Ok, thanks Condor. I'll just use a flag in the handler.