Lazy dependencies and Environments #412
-
Hi, Ive got (probably) amateur question as I'm exploring the Composable Architecture. Most of the views in this graph have their own environments with their own env dependencies specified, yet not all of the environments should be wandering around throughout the whole life-cycle of the app. Currently that's the case in the project Im working on. All environments that are used within the app are initialized at the top level. Is there a way how to actually defer the initialization time of specific environment down in the view hierarchy? Let's take an exact example: struct MeetingEnvironment {
let scrumTimer: ScrumTimer
....
} In the parent reducer for let detailViewReducer = Reducer<DetailViewState, DetailViewAction, DetailViewEnvironment>.combine(
meetingViewReducer.pullback(state: \DetailViewState.meetingState,
action: /DetailViewAction.meetingAction,
environment: { $0.meetingViewEnvironment }),
...
) My issue here is that If I wouldn't keep the reference to the instance of Maybe Im doing something wrong, so feel free to correct me. Thanks in advance! Best, Source code: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Do you have an example of this? |
Beta Was this translation helpful? Give feedback.
Do you have an example of this?
Reducer.pullback
captures a transformation of a global environment into a more local one, but that global environment should be as long living as your app's store, so thescrumTimer
shouldn't ever be deinitialized.