Results 1 to 4 of 4

Thread: Sprites fire too many events?

  1. #1
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,892
    Vote Rating
    543
      0  

    Default Sprites fire too many events?

    Is there a reason each sprite fires the beforedestroy, destroy and render events?

    I have a drawing application with several hundred sprites and I don't find these events useful.

    I think they just slow down the Ext.draw code. I searched the Ext.chart package... and I don't see that these events are used internally either.

    Code:
    Ext.define('Ext.draw.Sprite', {
        ....
        constructor: function(config) {
            ...
            me.addEvents(
                'beforedestroy',
                'destroy',
                'render',
                'mousedown',
                'mouseup',
                'mouseover',
                'mouseout',
                'mousemove',
                'click'
            );
            ...
        }
        ...

  2. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,147
    Vote Rating
    34
      0  

    Default

    In the Q&A I saw several users with cases using these events. Isn't it possible to disable them with an override?

  3. #3
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,892
    Vote Rating
    543
      0  

    Default

    Quote Originally Posted by tvanzoelen View Post
    In the Q&A I saw several users with cases using these events. Isn't it possible to disable them with an override?
    Perhaps I'm too critical... there's no beforerender event

  4. #4
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,892
    Vote Rating
    543
      0  

    Default Beta 3 changes

    There have been some performance improvement added in the Observable class for Beta 3, see code fragment below.
    Code:
    Ext.define('Ext.util.Observable', {
        ...
        constructor: function(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 || {};
            ...
        },
        ...
    So the sprite destroy method could be modified as recommended to take advantage of these changes. For example, if you are destroying 500 sprites, these changes will eliminate 1,000 function calls.
    Code:
    // current code
    destroy: function() {
        var me = this;
        if (me.fireEvent('beforedestroy', me) !== false) {
            me.remove();
            me.surface.onDestroy(me);
            me.clearListeners();
            me.fireEvent('destroy');
        }
    }
    
    // modified code to take advantage of Beta 3 changes
    destroy: function () {
        var me = this;
        if (!me.hasListeners.beforedestroy || me.fireEvent('beforedestroy', me) !== false) {
            me.remove();
            me.surface.onDestroy(me);
            me.clearListeners();
            if (me.hasListeners.destroy) {
                me.fireEvent('destroy');
            }
        }
    }

Posting Permissions

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