perf(platform-browser): cache plugin resolution in the EventManager
closes #12824
This commit is contained in:
parent
a965d11cce
commit
73593d4bf3
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue