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:
parent
85395bb9f0
commit
a8fc8d79f7
|
@ -52,7 +52,10 @@ struct HomeView: View {
|
||||||
transaction: .demo,
|
transaction: .demo,
|
||||||
route: nil
|
route: nil
|
||||||
),
|
),
|
||||||
reducer: .default.debug(),
|
reducer: SendReducer.default(
|
||||||
|
whenDone: { viewStore.send(.updateRoute(nil)) }
|
||||||
|
)
|
||||||
|
.debug(),
|
||||||
environment: ()
|
environment: ()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,6 +28,17 @@ extension SendReducer {
|
||||||
return .none
|
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
|
// Mark: - SendStore
|
||||||
|
|
Loading…
Reference in New Issue