2017-01-30 31 views
6

Neden publishReplay (1) .refCount() geç aboneler için son değer yeniden etmiyor? Neden Rxjs publishReplay (1) .refCount() yeniden etmiyor?

a = new Rx.Subject(); 
 
b = a.publishReplay(1).refCount(); 
 

 
a.subscribe(function(x){console.log('timely subscriber:',x)}); 
 
a.next(1); 
 
b.subscribe(function(x){console.log('late subscriber:',x)});
<script src="http://reactivex.io/rxjs/user/script/0-Rx.js"></script>

Beklenen çıkışı: İlk abone a abone

timely subscriber: 1 

cevap

1

timely subscribe: 1 
late subscriber: 1 

Fiili çıkış, ilk zaman akışı aktive refCount beri orada (Değil b ama a abone olduğu, çünkü orada yok olduğu), en az 1 abone, bu son loc kadar etkin değildir.

a = new Rx.Subject(); 
 
b = a.publishReplay(1).refCount(); 
 

 
b.subscribe(function(x){console.log('timely subscriber:',x)}); 
 
a.next(1); 
 
b.subscribe(function(x){console.log('late subscriber:',x)});
<script src="https://unpkg.com/rxjs/bundles/Rx.min.js"></script>

9

anda size a.next(1)publishReplay(1) gözlemlenebilir kaynağında (bu durumda Konu a) abone olmadı diyoruz çünkü bu olur ve bu nedenle iç ReplaySubject değerini almaz 1. Bu örnekte b.subscribe(...) olan zincirin sonunda abone olduğunuzda RxJS 5 operatörler arasındaki gerçek abonelik olarak

olur. Bkz: https://github.com/ReactiveX/rxjs/blob/master/src/Observable.ts#L96

Eğer operatörler sadece operatör bir örneğini alır ve yeni gözlemlenebilir atar lift() yöntemi sayesinde zincirleme subscribe() arayana kadar https://github.com/ReactiveX/rxjs/blob/master/src/operator/multicast.ts#L63