PDA

View Full Version : Sprites fire too many events?



LesJ
25 Jan 2012, 6:42 AM
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.


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

tvanzoelen
25 Jan 2012, 6:52 AM
In the Q&A I saw several users with cases using these events. Isn't it possible to disable them with an override?

LesJ
25 Jan 2012, 7:01 AM
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 ;)

LesJ
22 Feb 2012, 6:28 AM
There have been some performance improvement added in the Observable class for Beta 3, see code fragment below.

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.


// 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');
}
}
}