PDA

View Full Version : Question on mon() usage



arthurakay
17 Nov 2009, 12:08 PM
Let's say I define an element (like a ComboBox) as such:


var itemTemplateBox = new Ext.form.ComboBox({
allowBlank: true,
displayField: 'Value',
valueField: 'Key',
editable: false,
fieldLabel: 'Template',
mode: 'local',
selectOnFocus: true,
store: templateDataStore,
triggerAction: 'all',
typeAhead: true
});


I've read a handful of posts/blogs explaining the mon() method to assist with garbage collection. The first parameter passed to mon() is the element to-which you want the listener applied... so would this be the correct usage?



itemTemplateBox.mon(
itemTemplateBox,
'select',
function(box, record, index) {
if (record.get('Value') == '<< NONE >>') {
box.reset();
}
}
);


Technically, I could use the mon() method for the parent element of "itemTemplateBox" (like a form or toolbar). Does it matter?

hendricd
17 Nov 2009, 2:01 PM
@arthurakay --

You've got the basic premise down. ;)

Just understand that with mon and mun, listener removal is handled by any Component or subclass.

Think of it this way:


someComponent.mon(someObservableOrElement, listeners );

when someComponent is destroyed, all the mons-listeners are automatically removed for you.

Here (http://www.extjs.com/forum/showthread.php?p=408930#post408930) is another, albeit simple, example of its use.

arthurakay
17 Nov 2009, 2:05 PM
Thanks.

I figured that I was doing things correctly because I wasn't getting any errors, but that's not usually a good reason to assume things work as they should :D