-
Notifications
You must be signed in to change notification settings - Fork 205
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
base: master
Are you sure you want to change the base?
Домашнее задание по Flow.Федоров #129
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.
Привет. Оставил пару замечаний
@@ -4,21 +4,21 @@ import com.google.gson.annotations.SerializedName | |||
|
|||
data class Fact( | |||
@field:SerializedName("createdAt") | |||
val createdAt: String, | |||
val createdAt: String = "", |
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.
Зачем дефолтные значения?
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.
потому что я туповат и возвращал класс с дефолтными значениями когда делал приведение через as? понял свою ошибку и исправил
.map { | ||
when { | ||
it % 15 == 0 -> { | ||
emit("$it") |
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.
Можно вынести из when
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 val _catsFact = MutableStateFlow<Result>( | ||
Success(catsModel = Fact()) | ||
) | ||
val catsFact = _catsFact.asStateFlow() | ||
|
||
init { | ||
viewModelScope.launch { | ||
withContext(Dispatchers.IO) { |
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.
Это нужно убрать
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.
убрал переключение на dispatchers io , потому что если я правильно понял, то ретрофит под капотом и так ходит на io поток
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.
Привет. Оставил пару комментариев
) : ViewModel() { | ||
|
||
private val _catsLiveData = MutableLiveData<Fact>() | ||
val catsLiveData: LiveData<Fact> = _catsLiveData | ||
private val _catsFact = MutableStateFlow<Result?>(null) |
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.
Работать с нуллабл имхо не очень удобно. Добавь еще 1 наследник резалта, например, Initial
|
||
sealed class Result{ | ||
class Success(val catsModel: Fact) : Result() | ||
class Error(val error: Throwable?) : Result() |
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.
А в каком случае ексепшен будет нулл?
Поправил код после лекции
Обработка ошибки
Заменил лайвдату на стейт
Поправил падение приложения