Last active
November 18, 2020 20:51
-
-
Save hellsan631/7310408ba1377eb322b9055e541d4b78 to your computer and use it in GitHub Desktop.
Creates a proxy which helps for debugging of objects
This file contains hidden or 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
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 | |
}, | |
} | |
); | |
} |
This file contains hidden or 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
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