I want to merge ReactorKit
with RxFlow
. Is there an elegant idea how to bind any action or mutation to steps emitter likes PublishRelay
inside of Reactor
My sample
import ReactorKit
import RxFlow
class ViewModel: Reactor, Stepper {
let steps: PublishRelay<ItemsStep>
enum Action {
case itemSelected(Item.ID)
}
enum Mutation {
case itemSelectionResult(Item.Details) // ??
}
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .itemSelected(let id):
return ItemsService.fetch(by: id)
// ... ??? bind(to: steps)
// ... ??? map(Mutation.itemSelectionResult)
}
}
}
I would like to avoid observable do
methods with self capturing like
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .itemSelected(let id):
return ItemsService.fetch(by: id)
.do { [weak self] info in
self?.steps.accept(ItemsStep.details(info))
}
.map(Mutation.itemSelectionResult)
}
}