diff --git a/src/NodeBind.js b/src/NodeBind.js index d57c136..b7fbb6d 100644 --- a/src/NodeBind.js +++ b/src/NodeBind.js @@ -133,46 +133,7 @@ }; } - function isEventHandler(name) { - return name[0] === 'o' && - name[1] === 'n' && - name[2] === '-'; - } - - function eventBinding(el, name, value, oneTime) { - var eventType = name.substring(3); - if (oneTime) { - el.addEventListener(eventType, value); - return; - } - - var observable = value; - unbind(el, name); - function eventHandler() { - var fn = observable.discardChanges(); - fn.apply(this, arguments); - } - - el.addEventListener(eventType, eventHandler); - - var capturedClose = observable.close; - observable.close = function() { - if (!capturedClose) - return; - el.removeEventListener(eventType, eventHandler); - - observable.close = capturedClose; - observable.close(); - capturedClose = undefined; - }; - - return el.bindings[name] = observable; - } - Element.prototype.bind = function(name, value, oneTime) { - if (isEventHandler(name)) - return eventBinding(this, name, value, oneTime); - var conditional = name[name.length - 1] == '?'; if (conditional) { this.removeAttribute(name); diff --git a/tests/tests.js b/tests/tests.js index 4deddc9..4dbedf4 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -237,73 +237,6 @@ suite('Element attribute bindings', function() { }); }); -suite('Element event bindings', function() { - test('Basic', function(done) { - var element = testDiv.appendChild(document.createElement('div')); - var fooCount = 0; - var barCount = 0; - var model = { - fooHandler: function() { - fooCount++; - } - }; - - var binding = element.bind('on-foo', new PathObserver(model, 'fooHandler')); - - then(function() { - dispatchEvent('foo', element); - assert.strictEqual(fooCount, 1); - assert.strictEqual(barCount, 0); - - model.fooHandler = function() { - barCount++; - } - - }).then(function() { - dispatchEvent('foo', element); - assert.strictEqual(fooCount, 1); - assert.strictEqual(barCount, 1); - - binding.close(); - dispatchEvent('foo', element); - assert.strictEqual(fooCount, 1); - assert.strictEqual(barCount, 1); - - done(); - }); - }); - - test('Basic - oneTime', function(done) { - var element = testDiv.appendChild(document.createElement('div')); - var fooCount = 0; - var barCount = 0; - var model = { - fooHandler: function() { - fooCount++; - } - }; - - var binding = element.bind('on-foo', model.fooHandler, true); - - then(function() { - dispatchEvent('foo', element); - assert.strictEqual(fooCount, 1); - assert.strictEqual(barCount, 0); - - model.fooHandler = function() { - barCount++; - } - - }).then(function() { - dispatchEvent('foo', element); - assert.strictEqual(fooCount, 2); - assert.strictEqual(barCount, 0); - - done(); - }); - }); -}); - suite('Form Element Bindings', function() { setup(doSetup);