RXJS 5 .subscribe() without arguments
So a quick question. I've been using RxJS 5 for a few months now, and I've run into a bit of behavior that I don't really understand, as I haven't been able to look it up anywhere.
I'm in a situation where subscribing to an observable chain with simply .subscribe();
doesn't trigger the observable.
However, if I add an onNext callback (empty or not), the observable triggers, and the chain processes: .subscribe(() => {});
Can anyone explain why this behavior happens?
EDIT2 - Removed irrelevant example
.subscribe()
actually doesn't require any parameters, it will just create an emptyObserver
if none are given, which should work just as well.
It is possible though, that there are issues related to this in some of the 5.0.0-beta versions - in case you are using one of those versions, you should update to a more stable release.
const obs$ = Rx.Observable.of("Foo")
.do(() => console.log("triggered!"));
obs$.subscribe();
obs$.subscribe();
<script src="https://unpkg.com/rxjs@5.1.1/bundles/Rx.min.js"></script>
Thanks to Damian Hercun for informing that this was a now-fixed bug in RxJS 5.4.2.
Info:
https://github.com/ReactiveX/rxjs/pull/1935
https://github.com/ReactiveX/rxjs/issues/1921
链接地址: http://www.djcxy.com/p/95272.html上一篇: 简单媒体查询规则在页面刷新上发生变化