Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

removeEvent causes data inconsistency on custom events #2439

MarcosFernandes opened this Issue Oct 24, 2012 · 2 comments


None yet
2 participants

This is about core 1.4.5.
Class $events property gets inconsistent as you remove and then add custom events. That can be easily reproduced with this code:

var Test = new Class({Implements:Event});
var test = new Test();
var evt = function() { };
test.addEvent('customEvent', evt);
test.removeEvent('customEvent', evt);
test.addEvent('customEvent', evt);

As a result, the $events['customEvent'] property would be:
[undefined, function () {}]

I've checked the "removeEvent" method, it deletes the event function but it doesn't actually remove it from the array. I think it's the same situation as the code below:

var a = ['bananas'];
delete a[0];

The array value would be:
[undefined, 'oranges']

As one last note, I'm trying to port some code from Mootools 1.2.5, so maybe I'm doing something wrong.

Thank you.


arian commented Oct 24, 2012

Yes, but this doesn't really matter. .fireEvent still only fires the correct ones. This is done so removing events during a fireEvent still works correctly.

@arian arian closed this Oct 24, 2012

Thanks Arian. I believe the plugin I was porting was not properly designed because it was 'looping' inside $events array without checking if members were defined - it wasn't needed in previous 1.2.5.
I guess having "undefined" array members in applications that remove events frequently would cause unnecessary looping on "fireEvent" methods, this small issue is by far compensated with the feature you just described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment