Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.