-
Notifications
You must be signed in to change notification settings - Fork 186
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
Farsiyan V. HomeWork_06 RX #74
base: master
Are you sure you want to change the base?
Conversation
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.
Привет. Поправь плз
emitter.onNext(success) | ||
}, BackpressureStrategy.BUFFER) | ||
.distinctUntilChanged() | ||
.debounce(2000, TimeUnit.MILLISECONDS) |
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.
Дебаунс мне кажется совсем не для этого, почему интервал как в презенетере не подошел?
@@ -25,6 +26,10 @@ class LocalCatFactsGenerator( | |||
*/ | |||
fun generateCatFactPeriodically(): Flowable<Fact> { | |||
val success = Fact(context.resources.getStringArray(R.array.local_cat_facts)[Random.nextInt(5)]) | |||
return Flowable.empty() | |||
return Flowable.create<Fact?>({ emitter -> |
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.
Я думаю можно просто fromCallable
взять
|
||
class CatsViewModel( | ||
catsService: CatsService, | ||
localCatFactsGenerator: LocalCatFactsGenerator, | ||
val catsService: CatsService, |
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.
Тогда уж и private
)
getFacts(context) | ||
} | ||
|
||
fun getFacts(context: Context) { |
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.
В конструкторе же есть контекст, может тогда проще его сделать проперти?
val observable = Observable.interval(2, TimeUnit.SECONDS) | ||
.subscribeOn(Schedulers.io()) | ||
.flatMap { catsService.getCatFact() } | ||
.doOnError { |
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.
Это сайд-оператор, возьми лучше тот который в цепочке участвует и не придется 2 подписки делать
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.
если имеется ввиду лямбда t -> { } которая в subscribe методе, при retry() дело до него не доходит и он не вызывается
fun generateCatFactWhileError() { | ||
localCatFactsGenerator.generateCatFact() | ||
.subscribeOn(AndroidSchedulers.mainThread()) | ||
.subscribe(object: SingleObserver<Fact> { |
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.
Если ты реализовал только onSuccess, может не брать SingleObserver а просто лямбду передать в subscribe?
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.
👍
No description provided.