perf(core): don’t use `DomAdapter` nor zone for regular events
This commit is contained in:
parent
9c23884da4
commit
648ce5981b
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
|
|
||||||
import {getDOM} from '../dom_adapter';
|
|
||||||
import {EventManagerPlugin} from './event_manager';
|
import {EventManagerPlugin} from './event_manager';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -18,17 +17,25 @@ export class DomEventsPlugin extends EventManagerPlugin {
|
||||||
supports(eventName: string): boolean { return true; }
|
supports(eventName: string): boolean { return true; }
|
||||||
|
|
||||||
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
||||||
var zone = this.manager.getZone();
|
element.addEventListener(eventName, handler as any, false);
|
||||||
var outsideHandler = (event: any /** TODO #9100 */) => zone.runGuarded(() => handler(event));
|
return () => element.removeEventListener(eventName, handler as any, false);
|
||||||
return this.manager.getZone().runOutsideAngular(
|
|
||||||
() => getDOM().onAndCancel(element, eventName, outsideHandler));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addGlobalEventListener(target: string, eventName: string, handler: Function): Function {
|
addGlobalEventListener(target: string, eventName: string, handler: Function): Function {
|
||||||
var element = getDOM().getGlobalEventTarget(target);
|
let element: any;
|
||||||
var zone = this.manager.getZone();
|
switch (target) {
|
||||||
var outsideHandler = (event: any /** TODO #9100 */) => zone.runGuarded(() => handler(event));
|
case 'window':
|
||||||
return this.manager.getZone().runOutsideAngular(
|
element = window;
|
||||||
() => getDOM().onAndCancel(element, eventName, outsideHandler));
|
break;
|
||||||
|
case 'document':
|
||||||
|
element = document;
|
||||||
|
break;
|
||||||
|
case 'body':
|
||||||
|
element = document.body;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported event target ${target} for event ${eventName}`);
|
||||||
|
}
|
||||||
|
return this.addEventListener(element, eventName, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue