Skip to content

Commit

Permalink
Only one real listener per listen call
Browse files Browse the repository at this point in the history
Actually use event listener cache correctly

Fixes #2534 Polymer Gestures creates a new bound handler for every `listen` call
  • Loading branch information
dfreedm committed Oct 6, 2015
1 parent 45b1e5f commit 8bd380a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/standard/events.html
Expand Up @@ -80,8 +80,12 @@
* @param {string} methodName Name of handler method on `this` to call.
*/
listen: function(node, eventName, methodName) {
this._listen(node, eventName,
this._createEventHandler(node, eventName, methodName));
var handler = this._recallEventHandler(this, eventName, node, methodName);
// reuse cache'd handler
if (!handler) {
handler = this._createEventHandler(node, eventName, methodName);
}
this._listen(node, eventName, handler);
},

_boundListenerKey: function(eventName, methodName) {
Expand Down Expand Up @@ -140,6 +144,7 @@
anymore.
*/
unlisten: function(node, eventName, methodName) {
// leave handler in map for cache purposes
var handler = this._recallEventHandler(this, eventName, node, methodName);
if (handler) {
this._unlisten(node, eventName, handler);
Expand Down

0 comments on commit 8bd380a

Please sign in to comment.