Should Store
and Effect
evolve towards protocols?
#1177
Replies: 3 comments 5 replies
-
So, once this is implemented migrate could take place. The extensions on |
Beta Was this translation helpful? Give feedback.
-
We think
|
Beta Was this translation helpful? Give feedback.
-
Has any further thought been put into Effects as enums? I apologize if I have missed something but I have fallen behind on the videos and am working to catch up. The architecture I have been using is actually a variant of TCA from before it was published on github and actually uses enum Effects. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Without spoiling things, it is very likely that, in a near future, TCA will adopt typed (or protocolized) reducers. In other words, reducers will be values of types that conform to a protocol instead of merely being values of
Reducer<State, Action, Environment>
. Reducers will likely be types that conform to theReducerProtocol
which has two associated values:State
andAction
; theEnvironment
being dissolved into a set ofDependencies
that are exposed at will by the reducers. Usual reducers as we know them will continue to work, and adoption could be piecemeal.This transition invites reflection on performing this abstraction with other types in the library.
The first candidate is the
Store
. Right now, it is a class, generic over itsState
andAction
. Because they have the same generic signature, this information could be supported byReducers
instead. We can lias aStoreOf<Reducer> == Store<State, Action>
, but we lose the type ofReducer
while doing so, and we miss interesting specializations/optimizations where theReducer
type could play a role. IfStoreProtocol<Reducer: ReducerProtocol>
was a protocol, we could be able to alias the current stores asStore<AnyReducer<State, Action>>
, but also allow to conform other types toStoreProtocol
likeTestStore
of course, but even actors, opening the way to async stores/reducers. TheControlledStore
I presented as an experiment in #1176 is another example where we could have added additional behaviors to aStore
in a more streamlined way if we would only have to conform to a protocol.The second candidate is
Effect
. Right now,Effect
s are merely a wrapper of a publisher. Having them conform to a protocol (or maybe simply an enum) could potentially allow coalescing/simplifying reducers outcomes. Right now, it is quite inconvenient to poke inside an effect, and if they were more structured, we could probably post-process them in a more subtle manner. Furthermore, it is also likely that the library will try to cut its deep ties withCombine
. Effects being protocols could probably allow both systems to cohabit for a while and ease the migration.I'm not proposing any interface to these hypothetical protocols. I'm just starting the discussion in case some of you have interesting ideas on the matter!
Beta Was this translation helpful? Give feedback.
All reactions