Last active
November 14, 2017 22:32
-
-
Save gskachkov/0aa28a552de916d3546c73a925a19bf3 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 onChange = value => console.log(value); | |
const proxy = new Proxy({}, { | |
set: function (target, propertyName, newValue) { | |
const oldName = Reflect.get(target, propertyName); | |
onChange({ propertyName, oldName, newValue }); | |
return Reflect.set(target, propertyName, newValue); | |
}, | |
deleteProperty: function (target, propertyName) { | |
onChange({ propertyName, oldValue: Reflect.get(target, propertyName) }); | |
return Reflect.deleteProperty(target, propertyName); | |
} | |
}); | |
proxy.id = "foo"; // {propertyName: "id", oldName: undefined, newValue: "foo"} | |
delete proxy.id; // {propertyName: "id", oldValue: "foo"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment