[DEBUG] Trace only those events which have listeners. (#201)

The `DEBUG=*page npm run unit` is too verbose due to events spamming
the console.

This patch starts tracing emitted events only if there are any
listeners.
This commit is contained in:
Andrey Lushnikov 2017-08-03 15:20:31 -07:00 committed by JoelEinbinder
parent d8dd6ea140
commit 20ba447689

View File

@ -145,7 +145,7 @@ class Helper {
const method = Reflect.get(classType.prototype, 'emit');
Reflect.set(classType.prototype, 'emit', function(event, ...args) {
let argsText = [JSON.stringify(event)].concat(args.map(stringifyArgument)).join(', ');
if (debug.enabled)
if (debug.enabled && this.listenerCount(event))
debug(`${className}.emit(${argsText})`);
if (apiCoverage && this.listenerCount(event))
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, true);