-
Notifications
You must be signed in to change notification settings - Fork 132
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
#114 Add in memory preference #125
Conversation
Once #124 is merged to master by the owners, unnecessary commits should go away from this PR. |
Any suggestions where |
* pass the preference as a dependency and don't care about its state, simply mock the preference | ||
* using [Preference] interface. | ||
*/ | ||
class TestPreference<T>(private val key: String, private val defaultValue: T) : Preference<T> { |
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.
Any suggestions for name?
* In-memory implementation of [Preference] that can be used for testing purposes. Only use this | ||
* if your code under test depends on the changes in the preferences. Otherwise, if you need to | ||
* pass the preference as a dependency and don't care about its state, simply mock the preference | ||
* using [Preference] interface. |
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.
Would love to get any corrections, if any!
values.onNext(defaultValue) | ||
} | ||
|
||
override fun asObservable(): Observable<T> = values.distinctUntilChanged() |
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.
Was thinking if I should store values.distinctUntilChanged()
into a property and store it here.
* | ||
* @see [asObservable]. | ||
*/ | ||
private val values = BehaviorSubject.createDefault<T>(defaultValue) |
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.
Any RxJava edge cases that I need to look out for?
@@ -19,6 +20,7 @@ | |||
import static com.f2prateek.rx.preferences2.Preconditions.checkNotNull; | |||
|
|||
/** A factory for reactive {@link Preference} objects. */ | |||
@SuppressWarnings("WeakerAccess") |
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.
Removes warnings about public APIs not having strict enough visibility. Should this be suppressed per method?
compile deps.annotations | ||
compile deps.rxjava | ||
implementation deps.annotations | ||
implementation deps.kotlinStdlib |
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.
Should this be public? TestPreference.kt
doesn't expose any APIs from stdlib.
It's not package name, it's file name (or both)? Any suggestions? Not sure how to tune it in to allow |
Considering that I created only one new file, adding Kotlin as a new dependency probably wasn't a good idea, can revert to Java. Thoughts? |
* pass the preference as a dependency and don't care about its state, simply mock the preference | ||
* using [Preference] interface. | ||
*/ | ||
class TestPreference<T>(private val key: String, private val defaultValue: T) : Preference<T> { |
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.
How about naming this MemoryPreference
?
compileSdkVersion = 28 | ||
java8Version = JavaVersion.VERSION_1_8 | ||
javaVersion = JavaVersion.VERSION_1_7 | ||
kotlinVersion = '1.3.21' |
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.
I'm not sure we want to add a Kotlin dependency just for this.
Adding in-memory implementation of the
Preference
that can be used for testing purposes.Closes #114
Here's a primitive example of how and why this can be used. Let's say we have some dummy class that is backed by a boolean flag and boolean
Preference
:To test
Foo#isEnabled
property we need some implementation of thePreference
which would persist and change its state accordingly:Some remaining tasks: