Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
listeners patch fix
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxenko committed Jan 31, 2017
1 parent d21fa53 commit d04cc54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/h.js
Expand Up @@ -140,6 +140,7 @@ H.prototype.addEvent = function (name, listener) {
};

H.prototype.removeEvent = function (name) {
name = name.replace(/^on/, '').toLowerCase();
if (name in this.listeners) {
this.el.removeEventListener(name, this.listeners[name]);
delete this.listeners[name];
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "basic-virtual-dom",
"version": "0.2.4",
"version": "0.2.5",
"description": "Basic virtual dom implementation",
"main": "index.js",
"files": [
Expand Down
13 changes: 13 additions & 0 deletions tests/mocha-tests/attributes.test.js
Expand Up @@ -94,4 +94,17 @@ describe('Test attributes', function() {
patch(a, diff(a, b));
expect(a.props.onClick()).to.be.equal(2);
});

it('should patch replace listeners #2', function () {
var fail = false;
var listener1 = function() { fail = true; };
var a = h('div', { onClick: listener1}, '');
var b = h('div', { tabindex: 0} , '');

var dom = a.render();
patch(a, diff(a, b));

dom.click();
expect(fail).to.be.false;
});
});

0 comments on commit d04cc54

Please sign in to comment.