Optimize Emitter._installEvents()

Check for #_eventTypes first, no need to do anything if they don't exist.
This commit is contained in:
Jürg Lehni 2016-02-03 09:46:25 +01:00
parent 922a502ee2
commit 0f084eaf02

View file

@ -107,16 +107,18 @@ var Emitter = {
fire: '#emit', fire: '#emit',
_installEvents: function(install) { _installEvents: function(install) {
var handlers = this._callbacks, var types = this._eventTypes,
handlers = this._callbacks,
key = install ? 'install' : 'uninstall'; key = install ? 'install' : 'uninstall';
for (var type in handlers) { if (types) {
if (handlers[type].length > 0) { for (var type in handlers) {
var types = this._eventTypes, if (handlers[type].length > 0) {
entry = types && types[type], var entry = types[type],
func = entry && entry[key]; func = entry && entry[key];
if (func) if (func)
func.call(this, type); func.call(this, type);
} }
}
} }
}, },