Create a reducer to go back `Home` when finished sending

This is done as a seperate commit to demonstrate composing routing
logic where a 'child' feature can send messages to a 'parent'.
This commit is contained in:
Daniel Haight 2021-11-21 14:28:11 +00:00
parent 85395bb9f0
commit a8fc8d79f7
2 changed files with 15 additions and 1 deletions

View File

@ -52,7 +52,10 @@ struct HomeView: View {
transaction: .demo,
route: nil
),
reducer: .default.debug(),
reducer: SendReducer.default(
whenDone: { viewStore.send(.updateRoute(nil)) }
)
.debug(),
environment: ()
)
)

View File

@ -28,6 +28,17 @@ extension SendReducer {
return .none
}
}
static func `default`(whenDone: @escaping () -> Void) -> SendReducer {
SendReducer { state, action, _ in
switch action {
case let .updateRoute(route) where route == .showApprove(route: .showSent(route: .done)):
return Effect.fireAndForget(whenDone)
default:
return Self.default.run(&state, action, ())
}
}
}
}
// Mark: - SendStore