-
Notifications
You must be signed in to change notification settings - Fork 188
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
Kulish D. Flow Homework #64
base: master
Are you sure you want to change the base?
Conversation
2. Поменяйте реализацию с `LiveData` на `StateFlow` 3. В случае если возникнет ошибка в стриме, нужно заэмитить айтем `Result.Error`* *Создать sealed класс `Result`. Унаследовать от него классы `Success<T>`, `Error`. Использовать эти классы как стейт необходимый для рендеринга/отображени ошибки
catsRepository.listenForCatFacts().collect { | ||
_catsLiveData.value = it | ||
} | ||
withContext(Dispatchers.Main) { |
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.
а нужна ли нам смена контекста, если viewmodelscope все запускает на Main диспатчере?
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.
Нет не нужна, забыл что viewmodelscope на Main-е )
@@ -14,8 +19,25 @@ class MainActivity : AppCompatActivity() { | |||
val view = layoutInflater.inflate(R.layout.activity_main, null) as CatsView | |||
setContentView(view) | |||
|
|||
catsViewModel.catsLiveData.observe(this){ | |||
view.populate(it) | |||
lifecycleScope.launch { |
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.
есть еще функция launchWhenStarted из ktx пакета, немного сократит код
No description provided.