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

Домашнее задание по Flow.Федоров #129

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

Conversation

VladimirSergeevichFedorov

Поправил код после лекции

Обработка ошибки

Заменил лайвдату на стейт

Поправил падение приложения

Vladimir added 4 commits July 14, 2023 12:46
Поправил код после лекции

Обработка ошибки

Заменил лайвдату на стейт

Поправил падение приложения
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.

Привет. Оставил пару замечаний

@@ -4,21 +4,21 @@ import com.google.gson.annotations.SerializedName

data class Fact(
@field:SerializedName("createdAt")
val createdAt: String,
val createdAt: String = "",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Зачем дефолтные значения?

Copy link
Author

Choose a reason for hiding this comment

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

потому что я туповат и возвращал класс с дефолтными значениями когда делал приведение через as? понял свою ошибку и исправил

.map {
when {
it % 15 == 0 -> {
emit("$it")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Можно вынести из when

Choose a reason for hiding this comment

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

поправил, нашёл более подходящий оператор, для этого задания

private val _catsFact = MutableStateFlow<Result>(
Success(catsModel = Fact())
)
val catsFact = _catsFact.asStateFlow()

init {
viewModelScope.launch {
withContext(Dispatchers.IO) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Это нужно убрать

Copy link
Author

Choose a reason for hiding this comment

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

убрал переключение на dispatchers io , потому что если я правильно понял, то ретрофит под капотом и так ходит на io поток

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.

Привет. Оставил пару комментариев

) : ViewModel() {

private val _catsLiveData = MutableLiveData<Fact>()
val catsLiveData: LiveData<Fact> = _catsLiveData
private val _catsFact = MutableStateFlow<Result?>(null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Работать с нуллабл имхо не очень удобно. Добавь еще 1 наследник резалта, например, Initial


sealed class Result{
class Success(val catsModel: Fact) : Result()
class Error(val error: Throwable?) : Result()
Copy link
Collaborator

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