Created
December 6, 2017 01:18
-
-
Save OmgImAlexis/9a83a4982be0e0f741aebbf0325adc58 to your computer and use it in GitHub Desktop.
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
const emitKeyEvents = (obj, path = null) => { | |
return new Proxy(obj, { | |
get: (target, key, receiver) => { | |
if (typeof target[key] === 'object' && target[key] !== null) { | |
return emitKeyEvents(target[key], path ? `${path}.${key}` : key); | |
} | |
return Reflect.get(target, key, receiver); | |
}, | |
set: (target, key, value, receiver) => { | |
this.emit(path ? `${path}.${key}` : key, value); | |
return Reflect.set(target, key, value, receiver); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment