Skip to content

Commit 837e9b8

Browse files
committed
Make sure we only actually call _listen once
Gestures have counter code that should not be re-added with multiple identical `listen` calls
1 parent bf2f694 commit 837e9b8

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/standard/events.html‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@
8585
if (!handler) {
8686
handler = this._createEventHandler(node, eventName, methodName);
8787
}
88+
// don't call _listen if we are already listening
89+
if (handler._listening) {
90+
return;
91+
}
8892
this._listen(node, eventName, handler);
93+
handler._listening = true;
8994
},
9095

9196
_boundListenerKey: function(eventName, methodName) {
@@ -129,6 +134,7 @@
129134
methodName + '` not defined'));
130135
}
131136
};
137+
handler._listening = false;
132138
this._recordEventHandler(host, eventName, node, methodName, handler);
133139
return handler;
134140
},
@@ -148,6 +154,7 @@
148154
var handler = this._recallEventHandler(this, eventName, node, methodName);
149155
if (handler) {
150156
this._unlisten(node, eventName, handler);
157+
handler._listening = false;
151158
}
152159
},
153160

‎test/unit/events.html‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
document.body.removeChild(el);
154154
});
155155

156+
test('listen marks event handler as listening', function() {
157+
var handler = el._recallEventHandler(el, 'foo', el, 'missing');
158+
assert.equal(handler._listening, true, 'handler should be marked');
159+
});
160+
156161
test('Event handler fires only once', function() {
157162
el.fire('foo');
158163
assert.equal(el._warned.length, 1, 'event should fire only once');
@@ -171,9 +176,14 @@
171176
assert.ok(fn, 'should be cached');
172177
});
173178

179+
test('unlisten markes cached handler as not listening', function() {
180+
var handler = el._recallEventHandler(el, 'foo', el, 'missing');
181+
assert.equal(handler._listening, false, 'handler should not be listening');
182+
});
183+
174184
test('once unlistened, no handler fire', function() {
175185
el.fire('foo');
176-
assert.equal(el._warned.length, 1, 'event should not be handled anymore')
186+
assert.equal(el._warned.length, 1, 'event should not be handled anymore');
177187
});
178188
});
179189
});

0 commit comments

Comments
 (0)