PDA

View Full Version : how to remove events from eventbus ?



peter.pisljar@gmail.com
29 Dec 2011, 4:16 AM
hello.

how could i remove events i registered using this.control(); inside my controller ?



Ext.define('Weby.controller.ProductList', {
extend: 'Ext.app.Controller',

init: function() {
this.control({
'productlist': {
select: this.onSelect
}

});

},

onSelect: function(self, record, index, eOpts) {
alert("ProductList_onSelect");
var store = this.getStore('ProductList');
store.setIndexOfSelected(index);
}


i would like to remove onSelect event later on .....

thank you.

tavinashb
29 Dec 2011, 4:39 AM
try with suspendEvents (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.util.Observable-method-suspendEvents)() method of each component;

peter.pisljar@gmail.com
29 Dec 2011, 4:51 AM
i want to actualy remove it, as i am later destroying whole component.

when i load component the second time it fires event twice. (as two listeners are asociated with it)
thats why i want to completly remove the old listener. current workarroudn is to not use eventbus
(no this.control(...)) but to manualy add events to each control.

tavinashb
29 Dec 2011, 4:57 AM
try to remove event with removeListener (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.util.Observable-method-removeListener)() method before destroying the component.

peter.pisljar@gmail.com
29 Dec 2011, 5:11 AM
are you guessing or ... ?

i did removelistenr, clearlisteners, ... however noone of them are gonna help as event is not
on object but inside eventbus ....

tavinashb
29 Dec 2011, 5:39 AM
yes.....i think above method should work.
I have question - how can be your event is getting register 2 times?, If you are destroying component before creating new one.
I think your component is not getting destroyed at all.

please, correct me if i am wrong.

dougi
29 May 2012, 12:31 PM
i have the same problem. Have you find a solution ? I tried clearListeners too without success.

Thanks for your help, i am stuck.

dougi
30 May 2012, 3:49 AM
i finally only set render event via the control method. I don't forget to set the parameter single to true to make it only fires once and auto-unregisters itself. Inside it, i declare the other bunch of listeners i want to attach to any others components contained .

sdt6585
30 May 2012, 5:42 AM
Ext doesn't seem to like the idea of destroying controllers very much and the double event firing is particularly annoying. A few options that I've tried and had some success are:
Using Ext.create instead of App.getController to create an instance of a controller you have a little more control over initialization. You can break the control function out of init and call it independently only the first time that you create an instance of that controller. Note that you do actually have to call the init function as well with this method.
Don't destroy the controller, just destroy it's components. Give the controller a show function, and store what element it should render to. This may become a memory issue in a large single page app though that runs for a long period of time though.
I've only played with this in the console, but it seems like you could just set the reference in the event bus to undefined if you store a reference to the application. Note: you need a reference to the application object returned by Ext.application(), not the namespace object Ext creates based on the name config. I'm by no means promising that this won't break something else and haven't tested it on anything of substance, but it does seem to prevent events from firing.


var app = Ext.application(config)
app.eventbus.bus.eventName['#component query #string you #used'] = undefined;

dougi
30 May 2012, 6:30 AM
thanks for your answer AMsdt6585. I will keep this in mind in case my solution failed but up to now it works pretty well.

i look through my application controllers list. For each controller, i want to destroy, i call my custom cleanup methods then removed it..