ログイン時にReplySubjectから現在の値を取得しようとしています。現在のフローで購読すると、現在の値の代わりに前の値が返されます。だから、受け取ったものは、ログイン時の以前のものであり、現在のものではありません。 BehaviorSubjectに頼らなくても、ReplaySubjectのサブスクライブ時にObservableの現在の値を取得する方法はありますか?RXJS ReplaySubjectの現在の値を取得
stuff.service.ts:
private _stuffSubject = new ReplaySubject<any>();
private _stuff$: Observable<any> = this._someSubject.asObservable();
get stuff$() {
return this._stuff$;
}
private fetchStuff() {
return this.http.get('/stuff/current')
.map(data => {
return data.json()
})
.catch(err => {
console.debug(this.constructor.name, 'handled error ->', err.message);
return Observable.of(false);
})
.map(stuff => {
this._stuffSubject.next(stuff);
})
}
stuff.component.ts:
this.stuffService.stuff$
.subscribe(({stuff1, stuff2, stuff3}) => {
this.stuff1 = `${stuff1}`;
this.stuff2 = `${stuff2}`;
this.stuff3 = `${stuff3}`;
});
ます'_stuffSubject'を購読して現在のバッファを取得できますが、それがいつすべてのアイテムを放出したかを知ることはできません。 – martin