Joakim Forslund

    Joakim Forslund

    6 months ago
    For https://reduxkotlin.org
    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

    Alexander Black

    6 months ago
    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

    6 months ago
    @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
    Joakim Forslund

    Joakim Forslund

    6 months ago
    Thanks both of you, ill look into those solutions