1. #1
    Sencha User
    Join Date
    Dec 2008
    Location
    Lodz, Poland
    Posts
    173
    Vote Rating
    3
    grzegorz.borkowski is on a distinguished road

      0  

    Default How to register listener for all instances of the class ("statically")

    How to register listener for all instances of the class ("statically")


    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?

  2. #2
    Sencha User
    Join Date
    Dec 2008
    Location
    Lodz, Poland
    Posts
    173
    Vote Rating
    3
    grzegorz.borkowski is on a distinguished road

      1  

    Default Solved

    Solved


    It seems I've found solution: I've just discovered the Observable.observeClass method which allows for registering listeners globally on a class:
    Code:
    Ext.util.Observable.observeClass(Ext.data.Store);
    Ext.data.Store.on('write', function(...) {
        ...
    });
    Cool!

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Woot! Well done on the research! You hit the target!

  4. #4
    Sencha User KhodeN's Avatar
    Join Date
    Apr 2010
    Location
    Russia
    Posts
    7
    Vote Rating
    0
    KhodeN is on a distinguished road

      0  

    Cool


    Excellent! Big thanks!

Thread Participants: 2