Skip to content

Commit

Permalink
fix(DynamicFacetList): update selections of facet order change (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavFitz committed Jun 2, 2023
1 parent 10c5b72 commit 0f58334
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.algolia.instantsearch.filter.facet.dynamic.internal

import com.algolia.instantsearch.core.Callback
import com.algolia.instantsearch.core.connection.AbstractConnection
import com.algolia.instantsearch.filter.facet.dynamic.AttributedFacets
import com.algolia.instantsearch.filter.facet.dynamic.DynamicFacetListViewModel
import com.algolia.instantsearch.filter.facet.dynamic.SelectionsPerAttribute
import com.algolia.instantsearch.filter.state.FilterGroupDescriptor
Expand Down Expand Up @@ -30,6 +31,13 @@ internal class DynamicFacetListConnectionFilterState(
) : AbstractConnection() {

private val filterStateSubscription: Callback<Filters> = {
updateSelections()
}

private val facetOrderSubscription: Callback<List<AttributedFacets>> = {
updateSelections()
}
private fun updateSelections() {
val selectionsPerAttribute = viewModel.orderedFacets
.asSequence()
.map { it.attribute }
Expand Down Expand Up @@ -67,12 +75,14 @@ internal class DynamicFacetListConnectionFilterState(

override fun connect() {
super.connect()
viewModel.onFacetOrderChanged.subscribe(facetOrderSubscription)
viewModel.onSelectionsComputed.subscribePast(onSelectionsComputedSubscription)
filterState.filters.subscribePast(filterStateSubscription)
}

override fun disconnect() {
super.disconnect()
viewModel.onFacetOrderChanged.unsubscribe(facetOrderSubscription)
viewModel.onSelectionsComputed.unsubscribe(onSelectionsComputedSubscription)
filterState.filters.unsubscribe(filterStateSubscription)
}
Expand Down

0 comments on commit 0f58334

Please sign in to comment.