Send ChildA action from ChildB Effect

Hello :wave:t2:

I have a project with UIKit that I am currently re-writing using TCA. I have a quick question RE sending an Action from a different child inside another.

For example:

struct AppState {
var loginState: LoginState
var navigationState: NavigationState
var pagingState: PagingState
}

enum LoginAction { ... }
enum NavigationAction { ... }
enum PagingAction { ... }

Inside my loginReducer I want to send a NavigationAction inside an Effect if the login is successful. I am currently getting around this by using AppAction inside the loginReducer, then the Effect can be returned as

return Effect(
            value: .navigation(.setBase(.main))
        )
        .receive(on: environment.mainQueue)
        .eraseToEffect()

I know I could also send a loginSuccess action or the sorts and the navigationReducer could use AppAction and catch this one.

However; I am wondering if there are any other ideas for doing this? Ideally I only want the reducers to look at the actions and state that they should. So I still need some sort of way for the loginReducer Effect to be able to return a NavigationAction :thinking:

Note: To experiment I also used a global send function that the Effect can then just send inside a fireAndForget... Although that really isn't the approach that I want to use as it's also not easily testable.

Terms of Service

Privacy Policy

Cookie Policy