From d04cc5476b4f807087f7c2c9c00cb25fc3054305 Mon Sep 17 00:00:00 2001 From: Svetlana Linuxenko Date: Tue, 31 Jan 2017 12:09:19 +0200 Subject: [PATCH] listeners patch fix --- lib/h.js | 1 + package.json | 2 +- tests/mocha-tests/attributes.test.js | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/h.js b/lib/h.js index 1059dbe..42903a3 100644 --- a/lib/h.js +++ b/lib/h.js @@ -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]; diff --git a/package.json b/package.json index d319362..fe4942f 100644 --- a/package.json +++ b/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": [ diff --git a/tests/mocha-tests/attributes.test.js b/tests/mocha-tests/attributes.test.js index 0c6b951..e09d25b 100644 --- a/tests/mocha-tests/attributes.test.js +++ b/tests/mocha-tests/attributes.test.js @@ -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; + }); }); \ No newline at end of file