Skip to content

Instantly share code, notes, and snippets.

@hellsan631
Last active November 18, 2020 20:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellsan631/7310408ba1377eb322b9055e541d4b78 to your computer and use it in GitHub Desktop.
Save hellsan631/7310408ba1377eb322b9055e541d4b78 to your computer and use it in GitHub Desktop.
Creates a proxy which helps for debugging of objects
function createLogHandler(obj: any) {
return new Proxy(
obj,
{
get(target: any, key: any) {
console.groupCollapsed(`Reading from ${key}`)
console.log(`target: ${JSON.stringify(target)}`)
console.log(`value: ${JSON.stringify(target[key])}`)
console.trace()
console.groupEnd()
return target[key];
},
set(target: any, key: any, value: any) {
console.groupCollapsed(`Setting value ${key} as ${value}`)
console.log(`old value: ${JSON.stringify(target[key])}`)
console.trace()
console.groupEnd()
target[key] = value;
return true
},
}
);
}
function logTrace(traceTitle: string) {
console.groupCollapsed(traceTitle)
console.error(traceTitle)
console.trace()
console.groupEnd()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment