Continued from Subscriptions · Issue #16 · pointfreeco/swift-composable-architecture · GitHub
Several people have expressed the desire to add something like Elm's subscriptions to TCA. Please read the original github issue for context, but tldr; version is "Effects depend on the whole history of Actions, while Subscriptions only depend on the latest State (useful not just in time-travel debugger but thats the extreme example we should be thinking of)".
[WIP] subscriptions by pteasima · Pull Request #1 · pteasima/swift-composable-architecture · GitHub contains an incomplete and naive prototype implementation, mostly meant to serve as a talking point. It shows that composability can work. Next step is to figure out whether this could be maintained as a separate add-on to TCA. One potential option is to have a ReducerWithSubscriptions
(better name please ) type that we can convert to a regular
Reducer
before passing it to a Store.
Another thing that hasnt been discussed much is the fact that if subscriptions
returns the same Subscription
as last time, we must distinguish:
- if that subscription is still running, do nothing
- if that subscription isnt running (presumably failed, since subscriptions usually dont finish), subscribe to the new one (restart it)
I originally thought we would need an API to inspect an effect's isRunning
state, but now I have some ideas how to do it without a Effect-inspection API. Its a little heavy handed. We would need to augment the actions with a didFinish(effectID: AnyHashable)
case (but dont let this fact leak to the public API of ReducerWithSubscriptions
). So far it only compiles in my head .
Im taking a little break from implementing this (but @opsb is lurking somewhere ). I hope the discussion can continue in the meantime.