So things are looking pretty great already, but now we can really start to flex our muscles. Because we have this sheet
reducer operator that handles all the details of how to integrate the parent and child domains, we get to layer on super powers with very little work.
Take effect cancellation as an example. It is very common to bring up a sheet in an application, and for that sheet to fire off effects. Those effects could be long-living, like timers, socket connections, etc., or the effect may just take a long time to finish, such as a slow network request.
We would love if those effects would just be automatically torn down and canceled when the sheet is dismissed. After all, if those effects produce any actions to be fed back into the system after the sheet is dismissed, then those actions will just go into the void. The child feature can’t react to those actions because there is no state to reduce on.
Now currently, with the tools that the Composable Architecture ships today, you do get a little bit of help in this area. If your effect is started from the .task
view modifier, which executes when the view appears, then that effect will be torn down when the view disappears.
However, it does not help with all of the effects that can happen at other times, such as when you tap a button to start a timer. That effect is not tied to the lifecycle of the view.
But this sheet
operator we have just developed does have the capability to coordinate all of this, and it’s super cool.