Results 1 to 4 of 4

Thread: How to avoid duplication of events in Controllers

  1. #1
    Sencha User mysticav's Avatar
    Join Date
    Mar 2007
    Location
    Mexico
    Posts
    528
    Vote Rating
    49
      1  

    Default How to avoid duplication of events in Controllers

    Let say I define this same event on 2 different controllers:

    Code:
    this.control({
                '#foo':{
                    click: this.bar
                }
            });
    Normally, if the 2 controllers are already loaded, the event will be fired twice.

    My question is, How to avoid the duplicate registration of the same event ?

    I'm looking for an option like this:

    Code:
    this.control({
                '#foo':{
                    click: this.bar,
                    single: true
                }
            });

    This also helps for Inheritance of controllers, where you have listeners on the parent Controller, and you don't want those events to be registered for each child Controller.

    Any idea ? I'm sure other people had to deal with this before.

  2. #2
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,883
    Vote Rating
    538
      0  

    Default

    Did you try to return false from this.bar? I wonder if this would stop the other controller from processing the event... Is this even what you are trying to accomplish? I know you can stop an application event if you return false.

  3. #3
    Sencha User mysticav's Avatar
    Join Date
    Mar 2007
    Location
    Mexico
    Posts
    528
    Vote Rating
    49
      0  

    Default

    That won't resolve my problem because my controllers are loaded dynamically by demand, so whichever comes first should register the event and avoid duplication from other controllers that can also be loaded.

    Normally extJS eventBus supports duplication of events. They are organized something like this:

    example:

    click:
    controller1 #mygrid
    controller2 #mygrid

    What I would like to do is to tell eventBus not to register an event if the itemId already exists under the same handler (click).

  4. #4
    Sencha User
    Join Date
    Oct 2011
    Location
    Vancouver, Canada
    Posts
    157
    Vote Rating
    14
      1  

    Default

    You should really init your controllers once only, preferably at startup.

    ExtJS is designed to have one instance of a controller, even if you have multiple instances of a view.

    Anyways, you can do something like this;

    Code:
    init: function(){
      if(this.inited){
        return;
      }
      this.inited = true;
    
      this.control(...);
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •