Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions microevent-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ MicroEvent.prototype = {
console.assert(typeof fct === 'function');
this._events = this._events || {};
if( event in this._events === false ) return;
console.assert(this._events[event].indexOf(fct) !== -1);
this._events[event].splice(this._events[event].indexOf(fct), 1);
length = this._events[event].length;
for (index = 0; index < length; index++) {
if (this._events[event][index] === fct) break;
}
console.assert(index < length);
if (index == length) return;
this._events[event].splice(index, 1);
},
trigger : function(event /* , args... */){
this._events = this._events || {};
Expand Down
11 changes: 8 additions & 3 deletions microevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* - pure javascript - server compatible, browser compatible
* - dont rely on the browser doms
* - super simple - you get it immediatly, no mistery, no magic involved
* - super simple - you get it immediately, no mystery, no magic involved
*
* - create a MicroEventDebug with goodies to debug
* - make it safer to use
Expand All @@ -18,8 +18,13 @@ MicroEvent.prototype = {
},
unbind : function(event, fct){
this._events = this._events || {};
if( event in this._events === false ) return;
this._events[event].splice(this._events[event].indexOf(fct), 1);
if (event in this._events === false) return;
length = this._events[event].length;
for (index = 0; index < length; index++) {
if (this._events[event][index] === fct) break;
}
if (index == length) return;
this._events[event].splice(index, 1);
},
trigger : function(event /* , args... */){
this._events = this._events || {};
Expand Down
11 changes: 10 additions & 1 deletion tests/bad.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ b.trigger("blerg", "no")

c = {}
MicroEvent.mixin(c)
c.bind('foo',function(bar){console.log(bar)})
fooFunc = function(bar){console.log(bar)};
c.bind('foo', fooFunc)


console.log("")
console.log("You should see 'bar' once only:");
console.log("")
c.trigger('foo','bar')
c.unbind('foo', fooFunc);
c.trigger('foo', 'bar');