https://kotlinlang.org logo
#redux
Title
# redux
j

Joakim Forslund

03/03/2022, 11:46 AM
For https://reduxkotlin.org
Copy code
fun subscribe(onChanged: (AppState) -> Unit):StoreSubscription {
    return store.subscribe { onChanged(store.state) }
}
What would be the easieast way to make this more generic to listen to a specific state rather than the appstate? Obviously making each state inherit from a base class or interface is one way, but is there a more functional way?
a

Alexander Black

03/10/2022, 11:52 PM
I don’t use reduxkotlin, so I cannot say for sure this’ll work, but I think this plugin is what you’re looking for: https://github.com/reduxkotlin/Reselect
I’ve been using https://github.com/ReKotlin/ReKotlin which has that built in… the only downside to ReKotlin as it currently stands there’s no thread safe store, so you’d either have to write some locks yourself or be ready for some race conditions. 😂
e

Emanuel Moecklin

03/21/2022, 12:50 PM
@Joakim Forslund I'm using https://github.com/reduxkotlin/Reselect to subscribe to substate, it also makes sure to call the "listener" only if substate changes (memoized selector)
Note it's not maintained any more but it's only two files so you could easily just copy it into your codebase. It also has a nasty bug that was never fixed in the original repo: https://github.com/reduxkotlin/Reselect/issues/9. I made a fix in https://github.com/1gravity/redux-kotlin-select/commit/18c6cd5a16ff15eec28d0bc9e7fff68463f18364
j

Joakim Forslund

03/21/2022, 1:00 PM
Thanks both of you, ill look into those solutions
👍 1
6 Views