Revert "fix(core): should use native addEventListener in ngZone (#20672)"

This reverts commit 65a2cb8307.
This commit is contained in:
Miško Hevery 2017-11-29 14:56:29 -06:00
parent f3c5481181
commit ba850b36de
2 changed files with 28 additions and 43 deletions

View File

@ -154,8 +154,7 @@ export class DomEventsPlugin extends EventManagerPlugin {
let callback: EventListener = handler as EventListener;
// if zonejs is loaded and current zone is not ngZone
// we keep Zone.current on target for later restoration.
if (zoneJsLoaded) {
if (!NgZone.isInAngularZone() || isBlackListedEvent(eventName)) {
if (zoneJsLoaded && (!NgZone.isInAngularZone() || isBlackListedEvent(eventName))) {
let symbolName = symbolNames[eventName];
if (!symbolName) {
symbolName = symbolNames[eventName] = __symbol__(ANGULAR + eventName + FALSE);
@ -186,18 +185,6 @@ export class DomEventsPlugin extends EventManagerPlugin {
element[ADD_EVENT_LISTENER](eventName, globalListener, false);
}
} else {
// if zone.js loaded and we are in angular zone, we don't need to
// use zone.js patched addEventListener
const wrappedCallback = function() {
return self.ngZone.run(callback, this, arguments as any);
};
zoneJsLoaded.apply(element, [eventName, wrappedCallback, false]);
// we just use the underlying removeEventListener
return () => element[REMOVE_EVENT_LISTENER].apply(
element, [eventName, wrappedCallback, false]);
}
} else {
// use zone.js patched addEventListener or native addEventListener if zone.js not loaded
element[NATIVE_ADD_LISTENER](eventName, callback, false);
}
return () => this.removeEventListener(element, eventName, callback);
@ -209,8 +196,6 @@ export class DomEventsPlugin extends EventManagerPlugin {
if (!underlyingRemove) {
return target[NATIVE_REMOVE_LISTENER].apply(target, [eventName, callback, false]);
}
// if zone.js loaded and wrappedCallback not exists, the callback was added in different zone
let symbolName = symbolNames[eventName];
let taskDatas: TaskData[] = symbolName && target[symbolName];
if (!taskDatas) {

View File

@ -283,7 +283,7 @@ export function main() {
});
getDOM().dispatchEvent(element, dispatchedEvent);
expect(receivedEvents).toEqual([dispatchedEvent, dispatchedEvent]);
expect(receivedZones).toEqual([Zone.root.name, 'angular']);
expect(receivedZones).toEqual([Zone.root.name, 'fakeAngularZone']);
receivedEvents = [];
remover1 && remover1();