Have an issue with a Driver
on RxSwift. Have a view model who is listening to an initTrigger in a ViewController as follow.
let initTrigger = rx.viewWillAppear
.mapToVoid()
.asDriverOnErrorJustComplete()
This initTrigger
is used to bind to another Driver
on the view model
let shoppingCart: Driver<ShoppingCart>
let shoppingCart = input.initTrigger
.flatMapLatest {
self.getShoppingCartUseCase
.execute()
.asDriver(onErrorJustReturn: ShoppingCart())
}
getShoppingCartUseCase.execute()
returns Observable<ShoppingCart>
and is using RxRealm lo listen to changes to a database.
back on the view controller, I have subscribed to that shoppingCart
like this
output?.shoppingCart
.map {
print("Mapping")
return $0.lines.count == 0
}
.asObservable()
.bind(to: goToCartButton.rx.isHidden)
.disposed(by: bag)
I placed the print("Mapping")
to realize that this last Driver is being triggered constantly after making an action that modifies my model and triggers the Observable<ShoppingCart>
I mentioned before.
What I'm doing wrong here?
Thanks for your help.