perf(platform-browser): cache plugin resolution in the EventManager

closes #12824
This commit is contained in:
Ferhat 2016-11-11 16:18:00 -08:00 committed by Victor Berchet
parent a965d11cce
commit 73593d4bf3
1 changed files with 7 additions and 0 deletions

View File

@ -20,6 +20,7 @@ export const EVENT_MANAGER_PLUGINS: OpaqueToken = new OpaqueToken('EventManagerP
@Injectable()
export class EventManager {
private _plugins: EventManagerPlugin[];
private _eventNameToPlugin = new Map<string, EventManagerPlugin>();
constructor(@Inject(EVENT_MANAGER_PLUGINS) plugins: EventManagerPlugin[], private _zone: NgZone) {
plugins.forEach(p => p.manager = this);
@ -40,10 +41,16 @@ export class EventManager {
/** @internal */
_findPluginFor(eventName: string): EventManagerPlugin {
const plugin = this._eventNameToPlugin.get(eventName);
if (plugin) {
return plugin;
}
const plugins = this._plugins;
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
if (plugin.supports(eventName)) {
this._eventNameToPlugin.set(eventName, plugin);
return plugin;
}
}