https://kotlinlang.org logo
#compose
Title
# compose
l

Leland Richardson [G]

08/03/2019, 12:02 AM
i also haven’t used the above library, but pretty much all redux-like libraries will be able to easily interop with compose. Looking at the readme, and targeting current Compose APIs (which are subject to change), you could easily interop with ReKotlin like so:
Copy code
// normal API to create a store based on readme example
val mainStore = Store(
     reducer = ::counterReducer,
     state = null
)

// effect-based API to select/subscribe to store in composition
fun <TSlice, TState> Store<TState>.select(selector: (TState) -> TSlice) = effectOf<TSlice> {
  val result = +state { selector(state) }
  +onCommit(selector) {
    val observer = StoreSubscriber<TSlice> { result.value = it }
    subscribe(observer, selector)
    onDispose {
      unsubscribe(observer)
    }
  }
  result.value
}

// usage
@Composable fun SomeView() {
  val count = +mainStore.select { it.counter }
  Text("Count: $count")
}
👍 2
m

moetouban

08/03/2019, 4:45 AM
I anticipate that one day we will have jetpack Redux 🧌
p

Patrick Jackson

08/05/2019, 4:40 PM
I've started https://reduxkotlin.org in hopes of making a standard redux for kotlin. Just starting to look at integration with Compose, so this is helpful @Leland Richardson [G]. Redux pattern is simple to implement, but having an ecosystem would make it more powerful
Just tried the above and works wonderfully with redux-kotlin. Thanks for making this extensible
a

Antanas A.

08/06/2019, 8:39 AM
noo, please, stop redux cancer spread
2 Views