Skip to content

Commit

Permalink
Make sure we only actually call _listen once
Browse files Browse the repository at this point in the history
Gestures have counter code that should not be re-added with multiple identical
`listen` calls
  • Loading branch information
dfreedm committed Oct 8, 2015
1 parent bf2f694 commit 837e9b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/standard/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@
if (!handler) {
handler = this._createEventHandler(node, eventName, methodName);
}
// don't call _listen if we are already listening
if (handler._listening) {
return;
}
this._listen(node, eventName, handler);
handler._listening = true;
},

_boundListenerKey: function(eventName, methodName) {
Expand Down Expand Up @@ -129,6 +134,7 @@
methodName + '` not defined'));
}
};
handler._listening = false;
this._recordEventHandler(host, eventName, node, methodName, handler);
return handler;
},
Expand All @@ -148,6 +154,7 @@
var handler = this._recallEventHandler(this, eventName, node, methodName);
if (handler) {
this._unlisten(node, eventName, handler);
handler._listening = false;
}
},

Expand Down
12 changes: 11 additions & 1 deletion test/unit/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
document.body.removeChild(el);
});

test('listen marks event handler as listening', function() {
var handler = el._recallEventHandler(el, 'foo', el, 'missing');
assert.equal(handler._listening, true, 'handler should be marked');
});

test('Event handler fires only once', function() {
el.fire('foo');
assert.equal(el._warned.length, 1, 'event should fire only once');
Expand All @@ -171,9 +176,14 @@
assert.ok(fn, 'should be cached');
});

test('unlisten markes cached handler as not listening', function() {
var handler = el._recallEventHandler(el, 'foo', el, 'missing');
assert.equal(handler._listening, false, 'handler should not be listening');
});

test('once unlistened, no handler fire', function() {
el.fire('foo');
assert.equal(el._warned.length, 1, 'event should not be handled anymore')
assert.equal(el._warned.length, 1, 'event should not be handled anymore');
});
});
});
Expand Down

0 comments on commit 837e9b8

Please sign in to comment.