Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ImagesViewModel(

fun onFilterChanged(text: String) {
viewModelScope.launch(dispatcherProvider.viewModel) {
filter.emit(text)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For MutableStateFlow, you can update the value synchronously using filter.value = text instead of calling the suspending emit(text) function. Furthermore, because updating a StateFlow's value is synchronous and thread-safe, you do not need to launch a coroutine via viewModelScope.launch at all. You should remove the coroutine wrapper and update the value directly.

Suggested change
filter.emit(text)
filter.value = text

}
}

Expand Down