-
7 Feb 2013 1:57 PM #1
Can someone explain what the item in Ext.util.Observable.mon does?
Can someone explain what the item in Ext.util.Observable.mon does?
From the documentation,
Shorthand for addManagedListener.
Adds listeners to any Observable object (or Ext.Element) which are automatically removed when this Component is destroyed.
Available since: Ext 4
Parameters- item : Ext.util.Observable/Ext.ElementThe item to which to add a listener/listeners.
- ename : Object/StringThe event name, or an object containing event name properties.
- fn : Function (optional)If the ename parameter was an event name, this is the handler function.
- scope : Object (optional)If the ename parameter was an event name, this is the scope (this reference) in which the handler function is executed.
- options : Object (optional)If the ename parameter was an event name, this is the addListener options.
So in grid.feature.AbstractSummary, just to use a random example,
What is me.view.store representing in this case and what is me.view representing? What is their relationship to the listener?Code:init: function() { var me = this; // Summary rows must be kept in column order, so view must be refreshed on column move me.grid.optimizedColumnMove = false; me.view.mon(me.view.store, { update: me.onStoreUpdate, scope: me }); },
Is someone could expand upon the documentation and give me a few examples on mon I would appreciate it.
-
7 Feb 2013 2:02 PM #2
It's for listening to events on other observables that you want cleaned up when the current observable is destroyed.
In the example you posted, we want to listen to some things on the store so that we can react to them in the plugin. By using mon, those listeners will be automatically removed when the view is destroyed, so we don't need to clean them up manually.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
7 Feb 2013 2:04 PM #3
So the equivalent .on would be
and me.view is unneeded because there is no managed cleanup.Code:me.view.store.on({ update: me.onStoreUpdate, scope: me });
Did I understand you correctly?
-
7 Feb 2013 3:49 PM #4
Correct.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
8 Feb 2013 7:06 AM #5
Thanks a lot, that was helpful.
So in general should I be using managed listeners instead of ones I have to manually clean up?
-
8 Feb 2013 8:25 AM #6
No, you can't generalise in that way. As a rule of thumb you should be registering the listeners against whichever object will be destroyed first. Listeners get cleaned up automatically with either method, the difference is which object's destruction triggers the clean up.


Reply With Quote
