# redux

Joakim Forslund

03/03/2022, 11:46 AM
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?

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:
I’ve been using 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. 😂

Emanuel Moecklin

03/21/2022, 12:50 PM
@Joakim Forslund I'm using 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: I made a fix in

Joakim Forslund

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