in src/pubsub.js at line 30, you are assigning i and l before the initialization of the triggering loop, leading to a case where you can cause a fatal TypeError if your handlers unsubscribe function from the same event that cause them. This can be problematic if you use logic control to define which callbacks to execute when.
for (var i = 0, l = handlers[event].length; i < l; i++) {
handlers[event][i].apply(ctx, ctx.args);
}
This code reproduces the issue. Notice that "Done." is never logged.
PubSub.subscribe('test', function () {
console.log('function 1 called');
});
PubSub.subscribe('test', function () {
console.log('function 2 called');
console.log('removing listeners for "test"');
PubSub.unsubscribe('test');
});
PubSub.subscribe('test', function () {
console.log('function 3 called');
});
PubSub.publish('test');
console.log('Done.');