RxSwiftCommunity / RxSwiftExt

A collection of Rx operators & tools not found in the core RxSwift distribution
MIT License
1.32k stars 213 forks source link

pairwise broke BehaviorRelay #274

Open davidfuzju opened 1 year ago

davidfuzju commented 1 year ago

hi, I use pairwise with BehaviorRelay to listener the userInfo's changes, by compared with old and new, then make some animation.

Expected: use pairwise with behaviorRelay, when there is a new subscription, behaviorRelay will emit latest element and with the power of pairwise, subscription will get a old and new tuple Actual: use pairwise with behaviorRelay, behaviorRelay will stop emit latest element for new subscription

Anyone helps?

// use pairwise
UserDetailManager.shared
.userDetailUpdateRelay
.pairwise()
.subscribe(onNext: { [weak self] (old, new) in 
       // BehaviorRelay not emit latest element for subscription
       // thought I read the doc that pairwise will not emit anything until the source observable emits at least 2 elements
       // however, after behaviorRelay has emit > 2 elements, BehaviorRelay will not emit any element for the new subscription
})
 .disposed(by: rx.disposeBag)

// not use pairwise
UserDetailManager.shared
.userDetailUpdateRelay
.subscribe(onNext: { [weak self] data in 
        // BehaviorRelay will emit latest element for subscription
        // for example, A UIView as a observer to subscribe this relay will get the latest element to show something for user
})
 .disposed(by: rx.disposeBag)