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

Farsiyan V. HomeWork_06 RX #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Buzlighter
Copy link

No description provided.

Copy link
Collaborator

@antonkazakov antonkazakov left a 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)
Copy link
Collaborator

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 ->
Copy link
Collaborator

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,
Copy link
Collaborator

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) {
Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это сайд-оператор, возьми лучше тот который в цепочке участвует и не придется 2 подписки делать

Copy link
Author

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> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если ты реализовал только onSuccess, может не брать SingleObserver а просто лямбду передать в subscribe?

Copy link
Collaborator

@antonkazakov antonkazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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

Successfully merging this pull request may close these issues.

2 participants