dai-shi / proxy-compare

Compare two objects using accessed properties with Proxy
https://www.npmjs.com/package/proxy-compare
MIT License
283 stars 18 forks source link

feat: better support of Object.hasOwn and "in" #47

Closed indutny closed 1 year ago

indutny commented 1 year ago

Prior to this commit Object.hasOwn and in operator would mark object keys as tracked meaning that different values for the key would result in object being reported as changed even though the actual value was never read.

With this commit we start tracking hasKey and hasOwnKey separately from regular properties and check for the key presence/absence in isChanged.

indutny commented 1 year ago

So, this is basically fixing my LIMITATION notes, right?

Yes! I was unfamiliar with the code base when I sent you a DM so my suggestions looked like adding new things to the library. In reality, it turned out that you had most of it already implemented so I just had to fix the LIMITATIONS indeed.

The approach seems good. I would like to refactor for my preference. (Maybe, I can add some commits in this PR.) I will take some time to understand the code. Thanks.

Thank you! Feel free to commit whatever your like to this branch, and I'd be more than happy to answer any questions and clarify any behavior if you need that.

indutny commented 1 year ago

Alright, after a few tries, I think I came up with something better than my original take on fixing these two LIMITATIONS. PTAL when you'll get a chance :heart:

codesandbox-ci[bot] commented 1 year ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f09076b645a34c9299cbac01ac464f7543599f08:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
React Configuration
React Typescript Configuration