fat / bean

an events api for javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug?: Multiple custom events

bartsidee opened this issue · comments

We have a function that binds to multiple custom events, like so:

bean.add(element, 'player.onEnded.videoPlayer player.onStop.videoPlayer', handler);

But it turns out when we try to fire the event, it will only fire the function on the last event name. So with the above example:

# this is working fine
bean.fire(element, 'player.onStop');

# this is not working!
bean.fire(element, 'player.onEnded');

I did a quick test with the code and events are properly added, types is actually an arry with the two events:

L482 bean.js

for (i = types.length; i--;) addListener(element, types[i], fn, originalFn, args)

but it just will only fire the function on the last set event in the string. It looks like something with the fire event function is causing this issue.

Does anybody has an idea what is going on? I tested this in Chrome 19

I added a test to prove the case:
bartsidee@04f9967

This is actually working with jQuery, see example below:
http://jsfiddle.net/yp3xj/

Found the cause, it seems the first event is ignored when the event is added by the check if the event is not already in the registry:
https://github.com/bartsidee/bean/blob/master/src/bean.js#L381

Only the first event is added, since the iteration runs backwards. The rest is ignored.