This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
DistinctUntilChanged with different comparisons #24
Merged
StefMa
merged 14 commits into
master
from
feature/distinctuntilchanged_with_custom_comparator
Nov 6, 2016
Merged
DistinctUntilChanged with different comparisons #24
StefMa
merged 14 commits into
master
from
feature/distinctuntilchanged_with_custom_comparator
Nov 6, 2016
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rename DistinctComparator#isEquals() to compareWith(other) analog to Comparable#compareTo. This change should reflect the fact that not a equals comparison is required The equals comparator has to use strong references to work properly (default implementation) Alternatives: *new* WeakEqualsComparator, HashComparator Added missing copyright
first check for backpressure before positiong the "calculating..." state DistinctUntilChanged works now when hammering the button
…hanged analog to @CallOnMainThread
StefMa
suggested changes
Nov 4, 2016
|
||
private interface TestViewBadHash extends TiView { | ||
|
||
@DistinctUntilChanged(comparator = EqualsComparator.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name and comparator isn't equal. You say BadHash
(and argument is BadHash
) but using EqualsComparator
|
||
private interface TestViewBadEquals extends TiView { | ||
|
||
@DistinctUntilChanged(comparator = HashComparator.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name and comparator isn't equal. You say BadEquals
(and argument is BadEquals
) but using HashComparator
Rest LGTM |
@StefMa Thanks for pointing out the mistake in the tests! |
StefMa
approved these changes
Nov 6, 2016
StefMa
deleted the
feature/distinctuntilchanged_with_custom_comparator
branch
November 6, 2016 12:09
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #19 the current implementation of
@DistinctUntilChanged
using thehashCode()
of the arguments could cause problems.The new default implementation uses
equals()
instead ofhashcode()
. ADistinctComparator
can be set as argument of the annotation@DistinctUntilChanged(comparator = EqualsComparator.class)
. Three different implementations exist:EqualsComparator
(default) - usesequals()
for comparison and holds a strong reference to the previous arguementsWeakEqualsComparator
- usesequals()
for comparison and holds a weak reference to the previous arguments. Could call a method twice whengc()
kicks in.HashComparator
- old implementation usinghashCode()
for comparison. Doesn't hold references to the argumentsWhen writing tests I detected that the
DistinctUntilChangedInvocationHandler
swallows exceptions thrown by theTiView
. The same problem was already discovered when using the@CallOnMainThread
annotation 23034a0. I fixed it here accordinglyThese proguard rules are required: