From 8bd380ab85912ce1cc8a9b084eb4fd32b221215b Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Tue, 6 Oct 2015 14:39:18 -0700 Subject: [PATCH] Only one real listener per `listen` call Actually use event listener cache correctly Fixes #2534 Polymer Gestures creates a new bound handler for every `listen` call --- src/standard/events.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/standard/events.html b/src/standard/events.html index 86a51a14c9..926c31b311 100644 --- a/src/standard/events.html +++ b/src/standard/events.html @@ -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) { @@ -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);