1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    26
    Vote Rating
    1
    steve.brownlee is on a distinguished road

      0  

    Default ExtJS 4 MVC Architecture and Event Bubbling

    ExtJS 4 MVC Architecture and Event Bubbling


    I feel like I'm missing something so obvious, but I can't see it. Basically, I'm firing an event in a controller and I want the application to be able to listen to that event.

    In the controller's init() I'm establishing an event
    Code:
    this.addEvents('networkselected');
    this.enableBubble('networkselected');
    Then when someone selects a network, I fire the event

    Code:
    this.fireEvent('networkselected');
    How do I get my application to listen to this event. When I add the following code to my application's launch method, the event isn't handled.
    Code:
    launch: function() {
       this.addManagedListener(this, 
    	'networkselected',
    	function(){
    		alert('networkselected handled');
       });
    }
    Last edited by steve.brownlee; 3 Jun 2011 at 11:30 AM. Reason: formatting

  2. #2
    Ext JS Premium Member
    Join Date
    Oct 2009
    Posts
    29
    Vote Rating
    3
    iesdeveloper is on a distinguished road

      1  

    Thumbs up


    You can just fire the event in the app object itself from inside the controller:

    PHP Code:
    this.application.fireEvent('networkselected'); 
    Then in app object or in any other controllers:

    PHP Code:
    init : function() {
        
    this.application.addListener({
            
    'networkselected' this.onNetworkSelectedEvent,
        });

    I've been using this technique to send application-level event messages between controllers to reduce the coupling and it works pretty well so far.

  3. #3
    Sencha User
    Join Date
    Dec 2010
    Posts
    26
    Vote Rating
    1
    steve.brownlee is on a distinguished road

      0  

    Default


    This works great. It even allows me to bubble the event at the application level and let another object outside of the Ext application scope listen to it. Thanks so much!!

  4. #4
    Ext JS Premium Member
    Join Date
    Oct 2009
    Posts
    29
    Vote Rating
    3
    iesdeveloper is on a distinguished road

      0  

    Default


    No problem.

    The basic idea comes from this thread, where the OP goes a step further and creates a global app variable so you can fire the events from anywhere, not just controllers:

    http://www.sencha.com/forum/showthread.php?133931-Feedback-on-Application-Event-Pattern

  5. #5
    Sencha User
    Join Date
    Dec 2010
    Posts
    26
    Vote Rating
    1
    steve.brownlee is on a distinguished road

      0  

    Default


    That's great, because that's what I ended up doing. I created a application.eventBus object that everything can fire to/listen from.

  6. #6
    Sencha User
    Join Date
    Apr 2010
    Posts
    100
    Vote Rating
    0
    Dipish is an unknown quantity at this point

      0  

    Default


    Here's a related question: how do I prevent an event from bubbling? Kind of like e.stopPropagation() for DOM events. This is a VERY needed feature.

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi