Created
June 29, 2017 08:46
-
-
Save amatiasq/7db5ddccd351668aec46e3d3cef816ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable */ | |
let indent = 1; | |
function log(Class) { | |
const descriptors = {}; | |
Reflect.ownKeys(Class.prototype).forEach(key => { | |
const descriptor = Reflect.getOwnPropertyDescriptor(Class.prototype, key); | |
const {value} = descriptor; | |
descriptors[key] = descriptor; | |
if (key === 'constructor' || typeof value !== 'function') return; | |
const method = `${Class.name}.${key}`; | |
descriptor.value = function() { | |
const prefix = '|-'.repeat(indent) + method; | |
indent++; | |
console.debug(prefix, '(', ...arguments, ')'); | |
const result = value.apply(this, arguments); | |
console.debug(prefix, '<', result && result.$$typeof ? result.$$typeof : result); | |
indent--; | |
return result; | |
}; | |
}); | |
Class.prototype = Object.create( | |
Object.getPrototypeOf(Class.prototype), | |
descriptors | |
); | |
} | |
/* eslint-enable */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment