Skip to content

Conversation

@felangel
Copy link
Owner

Status

READY

Breaking Changes

NO

Description

  • fix: add @immutable to EquatableMixin

@felangel felangel added the bug Something isn't working label Oct 10, 2022
@felangel felangel self-assigned this Oct 10, 2022
@felangel felangel mentioned this pull request Oct 10, 2022
@felangel felangel merged commit 6de8b97 into master Oct 10, 2022
@felangel felangel deleted the fix/add-immutable-annotation-to-mixin branch October 10, 2022 15:24
@bambinoua
Copy link

bambinoua commented Dec 3, 2024

Why this? I have many entity classes which are mutable but use the equatable mixin for comparison. Now I need to fix more than 170 warnings (add ignore: must_be_immutable) or switch to the old version because of this change... :\

Could you please to explain how is the equatability related with immutability?

@felangel
Copy link
Owner Author

felangel commented Dec 3, 2024

Why this? I have many entity classes which are mutable but use the equatable mixin for comparison. Now I need to fix more than 170 warnings (add ignore: must_be_immutable) or switch to the old version because of this change... :\

Could you please to explain how is the equatability related with immutability?

This is described in the README:

Note: Equatable is designed to only work with immutable objects so all member variables must be final (This is not just a feature of Equatable - overriding a hashCode with a mutable value can break hash-based collections).

@bambinoua
Copy link

Then the question is how to compare two entities which properties are mutable? Let's say I have to Customer objects and I need to do something only if changes are detected:

final customerBeforeChange = Customer(...);
final customerAfterChange = customerBeforeChange.copyWith(...);
if (customerBeforeChange != customerAfterChange) {
  // do save
}

Sure, I can compare them property-by-property, but if the classes have too many properties, enumerating them will take time. The single initialization of props in Equatable was saving me.

@BirjuVachhani
Copy link

This has so much impact on our codebase that we decided to lock down on version 2.0.5 just to have piece of mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants