如何確保Observable
的訂戶將接收另一訂戶後的onNext
事件?RxSwift共享訂閱執行訂單
我的例子如下:
let firstNameObservable = firstName.asObservable().shareReplay(1)
let lastNameObservable = lastName.asObservable().shareReplay(1)
let bioObservable = bio.asObservable().shareReplay(1)
let websiteObservable = website.asObservable().shareReplay(1)
firstNameObservable.subscribe(onNext: { [unowned self] firstName in self.accountDetails.firstName = firstName }).disposed(by: disposeBag)
lastNameObservable.subscribe(onNext: { [unowned self] lastName in self.accountDetails.lastName = lastName }).disposed(by: disposeBag)
bioObservable.subscribe(onNext: { [unowned self] bio in self.accountDetails.bio = bio }).disposed(by: disposeBag)
websiteObservable.subscribe(onNext: { [unowned self] website in self.accountDetails.website = website }).disposed(by: disposeBag)
Observable.combineLatest(firstNameObservable, lastNameObservable, bioObservable, websiteObservable)
{ [unowned self] _, _, _, _ in return self.accountDetails.validForSignUp }
.bind(to: isValid)
.disposed(by: disposeBag)
我想爲去年combineLatest
結合上面它已經執行之後的任何的4 subscriptions
觸發。這是因爲只有在accountDetails
的屬性設置爲validForSignUp
才準確。
我知道這個問題的解決方案將是使validForSignUp
一個Variable
並觀察它,但是讓我們假設是不可能的。
isValid是變量嗎?如果可能的話,你應該避免使用變量和主題。 –