Package-level declarations

Types

Link copied to clipboard
@ObjCName(name = "ReduKtSelector", exact = true)
interface Selector<State, Selected>

Associates select function with isStateEqual and isSelectionEqual to improve selection performance.

Link copied to clipboard
fun interface SelectorEquality<in T>
Link copied to clipboard
typealias SelectorFunction<T, R> = (T) -> R

Type alias for state mapping function.

Link copied to clipboard

Enumerates possible cache options for SelectStateFlowProvider.

Link copied to clipboard

Provides a StateFlow for Selector to observe selected state.

Functions

Link copied to clipboard
fun <State, Selected> Store<State>.select(selector: Selector<State, Selected>): StateFlow<Selected>

Maps Store.state to a new StateFlow using given selector. Selector function is called only if Selector.isStateEqual returns false (by default it refers to equals). Also, selector function is not called before selected state is actually accessed using StateFlow.value or collected. Selector result is emitted only if Selector.isSelectionEqual returns false (by default it refers to equals).

Maps Store.state to a new StateFlow using given selector function. selector function is not called before selected state is actually accessed using StateFlow.value or collected. Also, it's not called if state is not changed. State is compared using equals so selection might be recalculated even if unrelated part of the state changed. However, if selection stays the same (again compared using equals), it's not emitted (just like every StateFlow). To optimize state selection, use select with Selector param.

Link copied to clipboard
fun <State, Selected> Selector(stateEquality: SelectorEquality<State> = SelectorEquality.Default, selectionEquality: SelectorEquality<Selected> = SelectorEquality.Default, selector: SelectorFunction<State, Selected>): Selector<State, Selected>

Creates a Selector that associates selector function with stateEquality and selectionEquality.

Link copied to clipboard

Creates a SelectStateFlowProvider with given cache settings.