View Full Version : How to register listener for all instances of the class ("statically")

19 Nov 2009, 8:50 AM
In many cases I need to register the listener "globally"/"statically", i.e. on all instances of some class: say all instances of Grid or Store. However, Ext doesn't give me a simple way to do it. You can simply register listener on the instance (either in initial config, or after creating the instance). But how to do it at once for all instances that will be created from now on?
In case of Components, I can override its constructor or initComponent method, call the parent, and then register the listener. I'm not sure if it is the best way, but it should work. But what in case of Ext.data.Store? It's not a Component, so I can't override constructor or initComponent method. So how to register "global" listener for, say, "write" event on all Stores?

19 Nov 2009, 11:28 AM
It seems I've found solution: I've just discovered the Observable.observeClass method which allows for registering listeners globally on a class:

Ext.data.Store.on('write', function(...) {

19 Nov 2009, 11:31 AM
Woot! Well done on the research! You hit the target!

9 Oct 2011, 11:13 PM
Excellent! Big thanks!