Easily capture all events on a component in ExtJS
When debugging an ExtJS application, you'll often find it useful to listen to all events fired by a specific component. There is actually a handy built-in static method to do this called Ext.util.Observable.capture().
Here's a handy snippet that simply logs the event name and all arguments:
Ext.util.Observable.capture(myObj, function(evname) {console.log(evname, arguments);})
Even better, if you're currently inspecting your component's main element in your browser's developer tools, you can do this:
Ext.util.Observable.capture(Ext.getCmp($0.id), function(evname) {console.log(evname, arguments);})
Where $0
is the currently selected element. Should work fine in Chrome, Firefox, Opera, Safari.
If you don't want those logs to pollute your console anymore, simply call releaseCapture on your object:
Ext.util.Observable.releaseCapture(myObj);
This removes all captures on a given object so you don't have to reference your listener explicitly (which was likely an anonymous function :)).
Bonus tip: also be sure to check out the observe method which does something similar but allows you to listen to all events fired by all instances of a given class.
Written by Dmitry Pashkevich
Related protips
5 Responses
Can i capture browsers events like say when the browser was maxmiised or minimised. ?
Sounds like you want to capture window resize events. Typicall you put all your components inside Ext.container.Viewport and use Ext's layout mechanism that automatically tracks window resizing. You can override it if you want to. Check out these two methods:
If you provide more details on what you're trying to do I'll try to help (here or on StackOverflow)
Any way can capture the scroll event of Tree Panel with EXTJS 4.2.1 and I am not using EXT Touch. and I did tried the following but without any lucks
panel.body.on("scroll",function(){console.log("scrolling")};
panel.el.on("scroll".function(){....});
panel.getTargetEl().on("scroll",function(){.....});
I am appreciate if anyone can point me a direction.
Best Regards
Tony Chu
Note : In Ext JS 5 capture function has been moved to Ext.mixin.Observable.capture
@jsfeutx Thanks for the heads up!