Skip to content

Commit

Permalink
For mozilla-mobile#12361 - Implement equals and hashCode methods for …
Browse files Browse the repository at this point in the history
…SearchRequest
  • Loading branch information
Alexandru2909 committed Jun 28, 2022
1 parent 8bda73a commit 9cdaf02
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import mozilla.components.browser.state.action.ContentAction
Expand All @@ -16,6 +17,7 @@ import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.search.SearchRequest
import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.base.feature.LifecycleAwareFeature
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
import mozilla.components.support.utils.ext.toNullablePair

/**
Expand All @@ -36,16 +38,10 @@ class SearchFeature(

override fun start() {
scope = store.flowScoped { flow ->
flow
.map { state ->
val tab = state.findTabOrCustomTabOrSelectedTab(tabId)
tab?.content?.searchRequest to tab?.id
}
flow.map { state -> state.findTabOrCustomTabOrSelectedTab(tabId) }
.ifChanged { it?.content?.searchRequest }
// Do nothing if searchRequest or sessionId is null
.mapNotNull { pair -> pair.toNullablePair() }
// We may see repeat values if other state changes before we handle the request.
// Filter these out.
.distinctUntilChangedBy { (searchRequest, _) -> searchRequest }
.mapNotNull { tab -> Pair(tab?.content?.searchRequest, tab?.id).toNullablePair() }
.collect { (searchRequest, sessionId) ->
performSearch(searchRequest, sessionId)
store.dispatch(ContentAction.ConsumeSearchRequestAction(sessionId))
Expand Down

0 comments on commit 9cdaf02

Please sign in to comment.