Results 1 to 2 of 2

Thread: How to listen to parent controller via fireEvent/listen

  1. #1
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    43
    Vote Rating
    1
      0  

    Question How to listen to parent controller via fireEvent/listen

    Hey,

    Quick example, I have an AbstractView/ViewController, and a bunch of different View/ViewController that all extend that abstractView. Lets say :

    Code:
    Ext.define('MyApp.view.abstract.AbstractView', {
        extend: 'Ext.panel.Panel',
        ...
    });
    
    
    Ext.define('MyApp.view.abstract.AbstractViewController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.abstract',
        ...
    
        someSharedEvent: function() {
            this.fireEvent('sharedEvent','whatever');
        }
    });
    
    Ext.define('MyApp.view.foo.Foo', {
        extend: 'MyApp.view.abstract.AbstractView',
        ...
    
    });
    
    
    Ext.define('MyApp.view.foo.FooViewController', {
        extend: 'MyApp.view.abstract.AbstractViewController,
        alias: 'controller.foo',
        ...
    });
    
    Ext.define('MyApp.view.bar.Bar', {
        extend: 'MyApp.view.abstract.AbstractView',
        ...
    });
    
    
    Ext.define('MyApp.view.bar.BarViewController', {
        extend: 'MyApp.view.abstract.AbstractViewController',
        alias: 'controller.bar',
        ...
    });
    AbstractView/ViewController is there for some shared items/events. I would like to listen to the abstractVC firing but it doesnt seem to work with the alias like this :

    Code:
    this.listen({
        controller: {
            'abstract': function() {
                //never called.
            },
            'foo': function() {
                //called.
            },
            'bar': function() {
                //called.
            }
        }
    })
    Whats the best way to achieve this, I hate duplicating all my listens. thanks!

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,385
    Answers
    3997
    Vote Rating
    1540
      0  

    Default

    The issue here is that the subclass controller only has one alias, it's own that you define, it doesn't have the abstract's alias because the abstract viewcontroller has that alias and two classes shouldn't have the same alias.



    The controller event domain does not check if a superclass of a controller has the alias, only if the current controller has the alias which the FooVC (from my fiddle) doesn't have the controller.abstract alias.

    This is the match method that determines if the controller has a listener:

    Code:
        match: function(target, selector) {
            var result = false,
                alias = target.alias;
            
            if (selector === '*') {
                result = true;
            } else if (selector === '#') {
                result = !!target.isApplication;
            } else if (this.idMatchRe.test(selector)) {
                result = target.getId() === selector.substring(1);
            } else if (alias) {
                result = Ext.Array.indexOf(alias, this.prefix + selector) > -1;
            }
            return result;
        }
    this is the important piece here:

    Code:
    result = Ext.Array.indexOf(alias, this.prefix + selector) > -1;
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Similar Threads

  1. [FIXED] [4.2.0 GA] Controller listen doesn't work with controller id
    By ukjbrown in forum Ext:Bugs
    Replies: 13
    Last Post: 19 Sep 2014, 4:49 AM
  2. [CLOSED] Controller fireEvent not always working
    By halcwb in forum Ext:Bugs
    Replies: 4
    Last Post: 9 Aug 2013, 1:37 PM
  3. fireEvent to controller in Native-android app
    By erwin8001 in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 3 Jun 2013, 4:54 AM
  4. FireEvent from View with itemId to Controller
    By pmlody in forum Sencha Touch 2.x: Discussion
    Replies: 3
    Last Post: 6 Feb 2013, 8:16 AM

Tags for this Thread

Posting Permissions

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