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 {getDOM} from '../dom_adapter';
|
||||
import {EventManagerPlugin} from './event_manager';
|
||||
|
||||
@Injectable()
|
||||
|
@ -18,17 +17,25 @@ export class DomEventsPlugin extends EventManagerPlugin {
|
|||
supports(eventName: string): boolean { return true; }
|
||||
|
||||
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
||||
var zone = this.manager.getZone();
|
||||
var outsideHandler = (event: any /** TODO #9100 */) => zone.runGuarded(() => handler(event));
|
||||
return this.manager.getZone().runOutsideAngular(
|
||||
() => getDOM().onAndCancel(element, eventName, outsideHandler));
|
||||
element.addEventListener(eventName, handler as any, false);
|
||||
return () => element.removeEventListener(eventName, handler as any, false);
|
||||
}
|
||||
|
||||
addGlobalEventListener(target: string, eventName: string, handler: Function): Function {
|
||||
var element = getDOM().getGlobalEventTarget(target);
|
||||
var zone = this.manager.getZone();
|
||||
var outsideHandler = (event: any /** TODO #9100 */) => zone.runGuarded(() => handler(event));
|
||||
return this.manager.getZone().runOutsideAngular(
|
||||
() => getDOM().onAndCancel(element, eventName, outsideHandler));
|
||||
let element: any;
|
||||
switch (target) {
|
||||
case 'window':
|
||||
element = window;
|
||||
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