javascript - rxjs中publishReplay().refCount()的作用
天蓬老师
天蓬老师 2017-04-11 12:14:56
0
1
1026

我找了很多资料都看的不是很明白,希望大家可以简单的说一说或者提供点资料,谢谢!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

répondre à tous(1)
PHPzhong
var subject$$ = new Rx.ReplaySubject();
subject$$.subscribe( x => console.log('sub',x) );

var observableA$ = Rx.Observable.of('test');
observableA$.subscribe(subject$$) ;

=======省略的写法========

var connectableObservable$ = Rx.Observable.of('test').multicast( new Rx.ReplaySubject())

//需要手动的去connect

var sub = connectableObservable$.connect();
connectableObservable$.subscribe( x => console.log('sub',x) );

//需要手动去unsubscribe unconnect

sub.unsubscribe()
=====这样很麻烦,使用引用计数 来自动connect unconnect====
var sourceA$ = connectableObservable$.refCount(); //stands for referenceCounting
var subA = sourceA$.subscribe( x => console.log('sub',x) )  
//ref 0->1    then  automatic connect
subA.unsubscribe()  
//ref 1-> 0 then  automatic unconnect
Rx.Observable.of('test').multicast( new Rx.ReplaySubject() ).refCount()   

->进一步省略

Rx.Observable.of('test').publishReplay().refCount() 



Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal