-
Notifications
You must be signed in to change notification settings - Fork 203
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
ДЗ HomeWork flow - Sergey Kudashkin #65
base: master
Are you sure you want to change the base?
Conversation
|
||
init { | ||
viewModelScope.launch { | ||
withContext(Dispatchers.IO) { | ||
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 диспачере
@@ -14,8 +19,23 @@ class MainActivity : AppCompatActivity() { | |||
val view = layoutInflater.inflate(R.layout.activity_main, null) as CatsView | |||
setContentView(view) | |||
|
|||
catsViewModel.catsLiveData.observe(this){ | |||
view.populate(it) | |||
// catsViewModel.catsLiveData.observe(this){ |
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.
неиспользуемый код можно почистить, оставлять за собой порядок - хорошоу
return flow { | ||
sampleRepository.produceNumbers().collect { | ||
emit(it.toString()) | ||
if(it % 15 == 0) emit("FizzBuzz") |
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, чтобы не было такой вложенности if-else
@@ -48,6 +69,22 @@ class SampleInteractor( | |||
* При любом исходе, будь то выброс исключения или успешная отработка функции вызовите метод dotsRepository.completed() | |||
*/ | |||
fun task4(): Flow<Int> { | |||
return flowOf() | |||
|
|||
return flow { |
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.
тут можно сделать немного элегантнее - sampleRepository.produceNumbers() возвращает flow, поэтому нам не нужно создавать новый flow. после вызова produceNumbers() можно посмотреть в сторону функций Flow.catch и Flow.onCompletion, они покроют 100% требований задачи
No description provided.