1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,339
    Vote Rating
    130
    LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all

      0  

    Default MVC hasListeners optimization

    MVC hasListeners optimization


    I think the hasListeners optimization is not very helpful when using the MVC pattern.

    I'd like to fire a custom event only if there's a controller that listens to this event, but how do I know that there's such a controller? The hasListeners hash doesn't include controller listeners.

    Do you see this as a problem?

    Code:
    Ext.define('Ext.util.Observable', {
    
        constructor: function(config) {
            var me = this;
    
            Ext.apply(me, config);
    
            // Hash of event "hasListeners" flags.
            // For repeated events in time-critical code, the firing code should use
            // if (!me.hasListeners.beforerender || me.fireEvent('beforerender', me) !== false) { //code... }
            // Bubbling the events counts as one listener.
            // The subclass may have already initialized it.
            me.hasListeners = me.hasListeners || {};
            ....

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Sencha Touch 2 I believe won't fire an event if there isn't a listener saving some performance. I had heard the Ext JS team talk about it but nothing has been implemented or promised.

    Back to your question. The global EventBus would have all the listeners from all controllers in it.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,339
    Vote Rating
    130
    LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Sencha Touch 2 I believe won't fire an event if there isn't a listener saving some performance. I had heard the Ext JS team talk about it but nothing has been implemented or promised.

    Back to your question. The global EventBus would have all the listeners from all controllers in it.
    Thanks for your answer. I have to say the MVC code is very well put together and it is easy to use. I did some Struts programming years ago... MVC on the client is more enjoyable.

  4. #4
    Sencha - Ext JS Dev Team dongryphon's Avatar
    Join Date
    Jul 2009
    Posts
    1,364
    Vote Rating
    135
    dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold

      0  

    Default


    In 4.1b3 there is a bug with MVC's EventBus and the hasListeners optimization. This has been fixed so that we can track listeners coming from controllers.
    Don Griffin
    Ext JS Development Team Lead

    Check the docs. Learn how to (properly) report a framework issue and a Sencha Cmd issue

    "Use the source, Luke!"

  5. #5
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,339
    Vote Rating
    130
    LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all LesJ is a name known to all

      0  

    Default


    Quote Originally Posted by dongryphon View Post
    In 4.1b3 there is a bug with MVC's EventBus and the hasListeners optimization. This has been fixed so that we can track listeners coming from controllers.
    I believe I found another bug in the EventBus...

    Here's my ref fragment:

    Code:
        refs: [{
            ref: 'viewDisplay',
            selector: '#viewDisplay'
        },
    viewDisplay is a checkbox.

    I get this checkbox by calling getViewDisplay()...

    I suspend events on the checkbox by calling checkbox.suspendEvents()...

    ...then I call checkbox.setValue(value);

    The change event gets fired anyway even though I suspended events. Is this a bug?

Thread Participants: 2