A Redux library for memoized state selectors. Forked from Reselect implementation. This repo deviates from the "original" repo considerably so please keep reeading.
Example usage:
Subscribe to a single sub state:
// Selecting to sub state subscribes to changes in that sub state.
// The Lambda will be executed when there isLoading` is changing.
val subscription: StoreSubscriber = store.select({ it.isLoading }) { isLoading ->
loadingIndicator.visibility = if (isLoading) View.VISIBLE else View.GONE
}
// Invoking the subcription does unsubscribe. Do this when appropriate for component lifecycle
subscription()
Subscribe to multiple sub states:
val multiSubscription = store.selectors {
select({ it.isLoading }) { isLoading ->
loadingIndicator.visibility = if (isLoading) View.VISIBLE else View.GONE
}
select({ it.name }) { name ->
nameTextView.text = name
}
}
// Unsubscribe when appropriate
multiSubscription()
How to add to project:
Requires Kotlin 1.4.0. Artifacts are hosted on maven central. For multiplatform, add the following to your shared module:
kotlin {
sourceSets {
commonMain { // <--- name may vary on your project
dependencies {
implementation("com.1gravitytlin:redux-kotlin-select:0.7.0-SNAPSHOT"
}
}
}
For JVM only:
implementation("com.1gravitytlin:redux-kotlin-select-JVM:0.7.0-SNAPSHOT"