Closed alfian0 closed 7 years ago
when i set addDisposableTo
will not printed
Hi @alfian0 ,
why do you think there is a problem with the code in this repo and not some external code?
I want implement Coordinator pattern with Rx but sometime at another project Observable object won't work,
We would need a more detailed description targeted at a specific component to investigate this.
@kzaher sorry, solved ...but still confusing, the code running well but we can printed or debug inside subscriber, I give arrow at this code
class OrderCoordinator: NavigationCoordinator { var navigationController: UINavigationController var archieveSelected: PublishSubject<Void> = PublishSubject<Void>() var disposeBag = DisposeBag() required init(navigationController: UINavigationController) { self.navigationController = navigationController self.archieveSelected .subscribe(onNext: { (_) in print("asd") <----------------------------------- // not printed, not paused when set breakpoint self.goToSomething() <------------------------------ // will executed and print on function block }) .addDisposableTo(by: self.disposeBag) self.archieveSelected .subscribe(onNext: { (_) in print("asd") <----------------------------------- // printed & paused when enable breakpoint }) } func start() { let viewModel = OrderViewModel() viewModel.archieveSelected .asObservable() .bind(to: self.archieveSelected) let viewController = OrderViewController(viewModel: viewModel) viewController.tabBarItem.image = #imageLiteral(resourceName: "icon_shop") viewController.tabBarItem.selectedImage = #imageLiteral(resourceName: "icon_shop_active") viewController.tabBarItem.isEnabled = false self.navigationController.viewControllers = [viewController] } func goToSomething() { print("something") <---------------------------- // printed and paused } }
Hi @alfian0 ,
there is an obvious difference between those two snippets of code.
self.archieveSelected
.subscribe(onNext: { (_) in
print("asd")
self.goToSomething()
})
.addDisposableTo(by: self.disposeBag) <------------------- difference
self.archieveSelected
.subscribe(onNext: { (_) in
print("asd")
})
Why do you think this is a bug?
I think you view model probably deallocates and disposeBag
terminates the subscription.
If there is some faulty APIs, then feel free to report another issue, but we can't debug non self contained code examples.
I want implement Coordinator pattern with Rx but sometime at another project Observable object won't work,
ViewController
ViewModel
Coordinator