0

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)

    }
  }

  • Why do you have `let steps: PublishRelay` in your Reactor in the first place? That doesn't feel right. – Daniel T. Oct 25 '22 at 22:04
  • @DanielT. Because of this component emits information about navigation, and as I understand correctly it should be out of presentation side. Any action which could be sent to reactor can effect to steps directly or lazy after some task execution like in my sample. I forgot add in my sample that my ViewModel implement navigation protocol – sergeifabian Oct 27 '22 at 07:32

0 Answers0