You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The identity of an event listener is determined by the tuple of
284
+
// [eventType, callback, thisArg], and influences addition and removal.
285
+
286
+
// If you try to add the same callback for a given event name twice, without
287
+
// distinguishing by its thisArg, the second addition will no-op.
288
+
obj.addEventListener(eventName,callback);
289
+
obj.addEventListener(eventName,callback);
290
+
obj.set('testName',1);
291
+
TKUnit.assert(receivedCount===1,'Expected Observable to fire exactly once upon a property change, having passed the same callback into addEventListener() twice');
292
+
obj.removeEventListener(eventName,callback);
293
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback) to remove all matching callbacks regardless of thisArg');
294
+
receivedCount=0;
295
+
296
+
// All truthy thisArgs are distinct, so we have three distinct identities here
297
+
// and they should all get added.
298
+
obj.addEventListener(eventName,callback);
299
+
obj.addEventListener(eventName,callback,1);
300
+
obj.addEventListener(eventName,callback,2);
301
+
obj.set('testName',2);
302
+
TKUnit.assert(receivedCount===3,'Expected Observable to fire exactly three times upon a property change, having passed the same callback into addEventListener() three times, with the latter two distinguished by each having a different truthy thisArg');
303
+
obj.removeEventListener(eventName,callback);
304
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback) to remove all matching callbacks regardless of thisArg');
305
+
receivedCount=0;
306
+
307
+
// If you specify thisArg when removing an event listener, it should remove
308
+
// just the event listener with the corresponding thisArg.
309
+
obj.addEventListener(eventName,callback,1);
310
+
obj.addEventListener(eventName,callback,2);
311
+
obj.set('testName',3);
312
+
TKUnit.assert(receivedCount===2,'Expected Observable to fire exactly three times upon a property change, having passed the same callback into addEventListener() three times, with the latter two distinguished by each having a different truthy thisArg');
313
+
obj.removeEventListener(eventName,callback,2);
314
+
TKUnit.assert(obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback, thisArg) to remove just the event listener that matched the callback and thisArg');
315
+
obj.removeEventListener(eventName,callback,1);
316
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback, thisArg) to remove the remaining event listener that matched the callback and thisArg');
317
+
receivedCount=0;
318
+
319
+
// All falsy thisArgs are treated alike, so these all have the same identity
TKUnit.assert(receivedCount===1,'Expected Observable to fire exactly once upon a property change, having passed the same callback into addEventListener() multiple times, each time with a different falsy (and therefore indistinct) thisArg');
329
+
obj.removeEventListener(eventName,callback);
330
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback) to remove all matching callbacks regardless of thisArg');
0 commit comments