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

Change set_state comparison method #1248

Open
Archmonger opened this issue Dec 9, 2024 · 0 comments
Open

Change set_state comparison method #1248

Archmonger opened this issue Dec 9, 2024 · 0 comments

Comments

@Archmonger
Copy link
Contributor

Archmonger commented Dec 9, 2024

Current Situation

Currently ReactPy using a function called strictly_equals to determine if set_state is setting itself to a duplicate value.

This sometimes relies on python's is keyword to check identity.

Proposed Actions

Using is to check equality in Python doesn't exactly behave the same as the javascript equivalent (Object.is). The current set_state design is effectively if the old/new memory references are the same, which doesn't equate to whether their values are the same. This is honestly a bit annoying, and results in a re-renders in a lot re-renders in scenarios were it was completely unneeded.

Python's __eq__ method is far more similar to JavaScript than Python's is. So realistically, we should be attempting to do an __eq__ check whenever possible.

if type(new) != type(old):
   return False

if hasattr(new, "__eq__") and hasattr(old, "__eq__"):
    return new == old

return new is old
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

1 participant