Closed Torinth closed 6 years ago
+1
I have a pr that fixes this issue but cant seem to push branches to make a pr with
what do I need to do in order to get my fix reviewed and possibly merged? I have not contributed to GitHub before so don't know what the normal process is
Hi if I use Object.defineProperty to create a property with setter logic and then also run watchjs over the object my existing setter logic is not retained. Something along these lines
var setter = (value) => { console.log(value) } var sample = {}; Object.defineProperty(sample, "blah, { get: getter, set: setter, enumerable: true, configurable: true }
sample.blah = "initial"
//shows console log
WatchJS.watch(sample, () =>{ console.log("in watch") }
sample.blah = "whatever"
//the console log in my custom setter above does not get called.
This would be good for applications that already have existing specific class and setter functionality to also be able to watch them without interfering with existing systems
heres example method that if I run this after watch both the custom setter logic and the watch logic fire
createProperty = function (object, propertyName, getter, setter) { var innerSetter = setter; var innerGetter = getter; var existing = Object.getOwnPropertyDescriptor(object, propertyName); if (existing) { if (existing.get) { console.log("found existing getter"); innerGetter = function innerGetter() { return existing.get(); }; } if (existing.set) { console.log("found existing setter"); innerSetter = function innerSetter(value) { existing.set(value); setter(value); }; } } Object.defineProperty(object, propertyName, { get: innerGetter, set: innerSetter, enumerable: true, configurable: true });