mootools/mootools-core — Issue #2226: Class events fail on first failure
Author: ibolmo
Created: 2012-01-19 09:06:33+00:00
State: open
Labels: bug, enhancement, optimization

(from [Lighthouse](https://mootools.lighthouseapp.com/projects/2706/tickets/1153-class-events-fail-on-first-failure))

OK - so title isn't very well understood but here's the main issue-
Whenever a broken function is fired using fireEvent, it will break the event loop.

This is not standard DOM events behavior, and it creates a blind dependency between different objects that might be listening to the same shared object.

I've set up a demo page here:
http://jsfiddle.net/6L2qf/

the first anchor shows how a Class behaves. The second how a DOM element behaves, and the third shows a fixed version of Events.

The fix itself is quite simple:

simply making each function fire with a setTimeout of 0 would solve this. This line (and the following line):
https://github.com/mootools/mootools-core/blob/master/Source/Class/...
simply would be replaced with

fn.delay(delay || 0, this, args);

I'll mention that this isn't a theoretical problem. On an app I'm working on, I have a Dispatcher Class that is used by many other objects. During dev, whenever there's a bug with one of these listeners, it hurts all others who listen to the same events. As I understand it, events are supposed to be a very useful means of decoupling between objects. This makes the events API unsafe for shared environments (a bit of exaggeration but you get my point).

Currently I simply use the fix above, but IMO this should be a part of the main implementation