Last active
June 14, 2017 13:52
-
-
Save MD4/aef3472fc9d45367e4cadcb71db7fb81 to your computer and use it in GitHub Desktop.
Refacto tool which highlight every use of a variable on an object.
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
/** | |
* Example: | |
* observe('myProp').on(myObject); | |
*/ | |
global.observe = (varName) => ({ | |
on: (object) => { | |
let value = object[varName]; | |
Object.defineProperty( | |
object, | |
varName, | |
{ | |
enumerable: true, | |
configurable: true, | |
get: () => console.trace( | |
`%cGET%c ${varName}`, | |
'color: green; font-weight: bold;', | |
'font-weight: bold;' | |
) || value, | |
set: (newValue) => console.trace( | |
`%cSET%c ${varName}`, | |
'color: red; font-weight: bold;', | |
'font-weight: bold;' | |
) || (value = newValue) | |
} | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment