Allow to use any arbitrary source of data for `stateBinding`
See original GitHub issueHi,
First of all, thanks for the awesome work! This framework looks very nice!
I want to propose an improvement of the stateBinding
feature. Currently, it is tighly bound to ReduxStore
. But the only really important thing is that it should observe changing state, and update the component.
So it would be nice if there was an alternative such as:
fun <S, CONT : Container> CONT.stateBinding(states: Flow<S>, factory: CONT.(S) -> Unit)
It would then allow to use any state management technology. Not only redux.
And the redux version could become an overload such as:
fun <S : Any, CONT : Container> CONT.stateBinding(store: ReduxStore<S>, factory: CONT.(S) -> Unit) =
stateBinding(store.asFlow(), factory)
fun <S : Any> ReduxStore<out S, *>.asFlow(): Flow<S> = channelFlow {
val unsubscribe = subscribe { state -> offer(state) }
awaitClose { unsubscribe() }
}.conflate()
The thing is, despite I like very much the philosophy behind redux and that state binding, I don’t like using Redux directly since it forces me to make my in-memory state serializable (which is awkward and limiting). And creating state management based on immutable state and pure reducer in Kotlin is far too easy to justify the complexity and limitation of using Redux.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Changed it to:
The return value is an unsubscribe function, just like with the redux store.
Until now unsubscribing was not even implemented in
StateBinding
class. I’ll take a look at this again 😃