From 0f084eaf029751cef8425d8a9866da6420e1cb69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 3 Feb 2016 09:46:25 +0100 Subject: [PATCH] Optimize Emitter._installEvents() Check for #_eventTypes first, no need to do anything if they don't exist. --- src/core/Emitter.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/Emitter.js b/src/core/Emitter.js index 39f0b4a23b..a83275ba5c 100644 --- a/src/core/Emitter.js +++ b/src/core/Emitter.js @@ -107,16 +107,18 @@ var Emitter = { fire: '#emit', _installEvents: function(install) { - var handlers = this._callbacks, + var types = this._eventTypes, + handlers = this._callbacks, key = install ? 'install' : 'uninstall'; - for (var type in handlers) { - if (handlers[type].length > 0) { - var types = this._eventTypes, - entry = types && types[type], - func = entry && entry[key]; - if (func) - func.call(this, type); - } + if (types) { + for (var type in handlers) { + if (handlers[type].length > 0) { + var entry = types[type], + func = entry && entry[key]; + if (func) + func.call(this, type); + } + } } },