Hi, I'm starting working with The Composable Architecture and so far so good, but I find some parts hard to understand. I found myself in a situation where I'm migrating part of a traditional UIKit app to SwiftUI+TCA approach. I managed to create a SwiftUI view and reducer for the first screen of a flow but I want to handle flow navigation with a global reducer, using pullback
.
This method creates the first screen with its own reducer
public func createWelcomeScreen() -> some View {
WelcomeView(
store: .init(
initialState: .init(),
reducer: createWelcomeReducer(),
environment: createWelcomeEnvironment()
)
)
}
Also I created a method to create the global reducer and combine it with the Welcome reducer
private func createGlobalReducer(
welcomeReducer: WelcomeReducer
) -> GlobalReducer {
let globalWelcomeReducer: GlobalReducer = welcomeReducer
.optional()
.pullback(
state: \.welcomeState,
action: /GlobalReducerDefinition.Action.welcome,
environment: { _ in
self.createWelcomeEnvironment()
})
return globalWelcomeReducer
.combined(with: GlobalReducerDefinition.create())
}
So, my problem now is, how can I inject the GlobalReducer into the WelcomeView since the later is expecting a WelcomeReducer
? Maybe what I want can't be achieved and need to handle navigation from each individual local reducer?
Thanks for your time.