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

Enable proxying of class instances by default #27

Closed Interpause closed 2 years ago

Interpause commented 2 years ago

I am using react-tracked to handle the game state of a board game I am making. However, since proxy-compare ignores class instances by default, none of the render optimizations react-tracked offers work.

Currently, createProxy() only proxies objects and arrays. This can be fixed by using markToTrack() on class instances, but if the class contains nested class instances, it requires the user to recursively mark everything. Doing so, react-tracked is able to track nested class instances within my use case at least. Hence, could it be possible to allow createProxy() to also proxy class instances by default? If not, what are the pitfalls of doing so?

dai-shi commented 2 years ago

I have once tried with valtio, but proxying any class instances leads unpredictable results. For example, it will proxy Date, or whatever we don't expect. We could technically make markToTrack to accept custom function for more control, but I'm not sure if most developers can use it.

it requires the user to recursively mark everything. Doing so, react-tracked is able to track nested class instances within my use case at least.

So, what you did is the expected approach by the design. tbh, I'm surprised you made it work with the current documentation.

Thanks for the feedback. Hope it makes sense.

Interpause commented 2 years ago

Yup, thanks