Skip to content

Commit

Permalink
Merge pull request #49 from JacksonTian/fix_unbind_issue
Browse files Browse the repository at this point in the history
Fix unbind issue, fix #48
  • Loading branch information
JacksonTian committed Mar 27, 2014
2 parents c89ea57 + 8bef8dd commit c54cefe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/eventproxy.js
Expand Up @@ -114,7 +114,6 @@
if (callback === list[i]) {
debug('Remove a listener of %s', eventName);
list[i] = null;
break;
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/test.js
Expand Up @@ -105,6 +105,23 @@ describe("EventProxy", function () {
assert.equal(counter, 1, 'counter should have only been incremented once.');
});

it('bind function muti-times, then remove it', function () {
var ep = EventProxy.create();
var counter = 0;
var handler = function () {
counter += 1;
};
ep.bind('event', handler);
ep.trigger('event');
assert.equal(counter, 1, 'counter should be incremented.');
ep.bind('event', handler);
ep.trigger('event');
assert.equal(counter, 3, 'counter should be incremented.');
ep.unbind('event', handler);
ep.trigger('event');
assert.equal(counter, 3, 'counter should not incremented again.');
});

it('headbind/trigger', function () {
var ep = EventProxy.create();
var str = '';
Expand Down

0 comments on commit c54cefe

Please sign in to comment.