Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created June 29, 2017 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatiasq/7db5ddccd351668aec46e3d3cef816ce to your computer and use it in GitHub Desktop.
Save amatiasq/7db5ddccd351668aec46e3d3cef816ce to your computer and use it in GitHub Desktop.
/* 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