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

Discussion - another method for comparing content equality in place of Item.equals() #288

Closed
ValCanBuild opened this issue Sep 17, 2019 · 5 comments
Labels

Comments

@ValCanBuild
Copy link
Collaborator

I'd like to start making more quality of life improvements in the library.

Currently to do a content comparison of two Items which are the same (meaning, isSameAs returned true for them) Groupie uses the Java equals method.

This forces subclasses to override both equals and hashCode for correct implementations and creates unnecessary boilerplate. This is especially nasty in Kotlin projects which 99% of the time don't ever override equals thanks to data classes.

In the interest of a nicer API, I'd like to create a companion function to isSameAs that will be used for the areContentsTheSame DiffUtil callback.

My proposed name is hasSameContentAs but open to other suggestions. areContentsTheSame is also an option but then the name would be different from isSameAs.

Whatever that function is called the default implementation would use the equals to not break current implementations.

Thoughts?

@Zhuinden
Copy link
Collaborator

I intended to propose isContentEqualTo, but hasSameContentAs sounds better.

@khatv911
Copy link

Agree with this. Also we should have a separate section regarding diffing with groupie.

@scorpeeon
Copy link

I think it's a good idea, overriding hashCode() just for this reason can be a pain and shouldn't be necessary.
hasSameContentAs() sounds good to me.

@ValCanBuild
Copy link
Collaborator Author

PR created #292

@ValCanBuild
Copy link
Collaborator Author

Now deployed in 2.6.0 - thank you for the feedback

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

No branches or pull requests

4 participants