Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Revert support for binding to on-* as event handlers
Browse files Browse the repository at this point in the history
The current implementation lacks an important feature on which polymer is relying: the receiver of the function is the model (or the object most proximate to the path-value).

It's not clear to me at the moment how to achieve this with the current layering, so I'm reverting until we have a complete design -- as this implementation is interfering with polymers.

R=arv
BUG=

Review URL: https://codereview.appspot.com/48180043
  • Loading branch information
rafaelw committed Jan 6, 2014
1 parent 0810362 commit 05dca5c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 106 deletions.
39 changes: 0 additions & 39 deletions src/NodeBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
67 changes: 0 additions & 67 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 05dca5c

Please sign in to comment.