Mini-beta: @Reducer
+@CasePathable
macro bonanza
#2555
Closed
stephencelis
started this conversation in
Beta
Replies: 2 comments 5 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
-
After simply switching to |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We just opened a PR introducing some exciting new functionality to the Composable Architecture and would love your feedback before release. Be warned, we will have episodes diving into some of these tools soon, so if you don't want those topics spoiled, read no further!
Introducing: the
@Reducer
macroThere is a new
@Reducer
macro that can be used to define features in the Composable Architecture.Where one used to conform to the
Reducer
protocol, they can now apply the@Reducer
macro instead:The macro automatically conforms the type to the
Reducer
protocol, but it does a few more things along the way:It automatically annotates
Action
enums with the new@CasePathable
macro, which generates "case key paths" for your actions, which are actual Swift key paths that improve on the old, reflection-based API (/SomeEnum.someCase
) in many ways, including type inference, autocomplete, equatability and hashability, dynamic member lookup, performance, and more.All case path-based APIs in the library have been updated to support the new format:
It automatically annotates
State
enums (commonly found in TCA navigation) with@CasePathable
, as well as@dynamicMemberLookup
. This will allow you to slightly improve the verboseness of TCA's enum navigation tools:Because
@Reducer
automatically applies@CasePathable
inside, you largely won't have to worry about the@CasePathable
macro unless you want to work with other enums in an ergonomic fashion.It does some basic linting of your conformance.
TestStore.receive(\.action)
There is a new method on test stores for matching received actions via a case key path.
Case key paths chain nicely, which makes it possible to describe expected actions in a lightweight manner, even in the deepest of integration tests:
A
TaskResult
soft-deprecationThe
TaskResult
type was introduced in order to make it easier to conform a reducer'sAction
toEquatable
, but given the streamlinedTestStore.receive(\.action)
API, actions no longer need to go through the ceremony of anEquatable
conformance. As such,TaskResult
has been soft-deprecated in favor of using the vanillaResult
type that comes with Swift.IdentifiedAction
The
forEach
operator on reducers andForEachStore
have been enhanced to work with a new dedicated action type calledIdentifiedAction
. This action type provides a wrapper for a child element action and identifier that pairs nicely withIdentifiedArray
.Migrating an existing
forEach
can take a few steps.Identified actions benefit from the new case key path syntax and so actions received by test stores can be described using a case paths that chains into the action via subscript:
Even more action case key path helpers
In addition to the new
IdentifiedAction
, the existingPresentationAction
andStackAction
types have been enhanced with case key paths that can be used when receiving test store actions:Trying the beta
These new tools are already available on the
case-key-paths
branch. If you are using an up-to-date version of the Composable Architecture you should be able to point to this branch and start giving things a try. The changes should be fully backwards-compatible, so let us know if pointing to the new branch causes any problems!If you take things for a spin, please let us know (via Twitter, Mastodon, GitHub discussions, or our Slack community) if you have questions, comments, concerns, or suggestions!
Beta Was this translation helpful? Give feedback.
All reactions