Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defineProperty should consider that descriptor.value is undefined when calling handleChangeOnTarget #79

Open
Baumgaer opened this issue May 7, 2021 · 7 comments

Comments

@Baumgaer
Copy link

Baumgaer commented May 7, 2021

Hi there again :'D,

currently I am running into a strange Bug in combination with VUE.
VUE defines its own properties on an object but does not define a value on the propertyDescriptor.
on-change's defineProperty (line 132) method is assuming, that this is always set. In my case the "current" value is determined in a wrong way so that it is always undefined at the first time. You should check with

if ("value" in descriptor)

if it is avalable and use descriptor.get() otherwise

maybe it has to be checked earlyer to be sure that there is a change or not.

@DarrenPaulWright
Copy link
Collaborator

Could you provide a code example of this?

@Baumgaer
Copy link
Author

yes I could, buit I need some time.
Vue essentially overwrites existing properties with a property descriptor which does not have the property "value"

@DarrenPaulWright
Copy link
Collaborator

Ah, I think I understand now. I'll see what I can do.

@DarrenPaulWright
Copy link
Collaborator

After thinking about this, I believe onChange is behaving correctly. We intentionally trigger a change when a descriptor changes or is added, even if the value is undefined. We could add an option like ignoreDescriptorChanges that only triggers when the value changes. Does that sound like it would solve your problem?

@Baumgaer
Copy link
Author

Sounds like a solution but the value isn't undefined. It's just hidden under the get method of the descriptor and the value property of the descriptor is missing. So the callback wouldn't fire if this is get noticed. Then you can exchange the propertydescriptor without the need of "value"and give it only a get method while leaving the value of the observed object untouched. I think we don't want to check if a descriptor is changed so the option should sound like observeDescriptorChange. But maybe both is good.

@DarrenPaulWright
Copy link
Collaborator

So its converting a property with a value to a property with getters/setters that returns the same value? If that's the case, then in my opinion that constitutes a change to object. Can you filter these out by comparing the value and previous value?

@Baumgaer
Copy link
Author

No I can't. When VUE changes the propertyDescriptor, the old and the new Value are undefined.
I have to do an "Object.getOwnPropertyDescriptor" and call the getter of it to check if it is a propertyDescriptorChange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants