Thread
#compose
    l

    Leland Richardson [G]

    3 years ago
    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:
    // 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")
    }
    moetouban

    moetouban

    3 years ago
    I anticipate that one day we will have jetpack Redux :troll:
    p

    Patrick Jackson

    3 years ago
    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.

    3 years ago
    noo, please, stop redux cancer spread