I also asked this question on StackOverflow, so if you want some SO rep feel free to answer there.
I'm trying to subscribe to an Observable created from a Subject, and whenever I subscribe without an error handler I get the error this._subscribe is not a function. I found this question that described a similar error; but the answers didn't seem to fit my situation. Here is my code:
const subject = new Rx.Subject();
subject
.withLatestFrom(otherObservable)
.subscribe(
values => {
// some logic
}
);
I also tried:
const subject = new Rx.Subject();
subject
.withLatestFrom(otherObservable)
.subscribeOnNext(
values => {
// some logic
}
);
and I get the same error. Here is the stack trace when I try just subscribe:
Observable.Rx.Observable.observableProto.subscribe.observableProto.forEach (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2034:19)
WithLatestFromObservable.subscribeCore (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:4084:33)
WithLatestFromObservable.tryCatcher (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:63:31)
setDisposable [as action] (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2082:46)
ScheduledItem.invokeCore (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:896:33)
ScheduledItem.invoke (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:884:40)
runTrampoline (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:1125:37)
tryCatcher (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:63:31)
CurrentThreadScheduler.schedule (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:1141:45)
WithLatestFromObservable.Rx.ObservableBase.ObservableBase._subscribe (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2095:32)
WithLatestFromObservable.Rx.Observable.observableProto.subscribe.observableProto.forEach (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2034:19)
and this is the stack trace when I try subscribeOnNext
Observable.Rx.Observable.observableProto.subscribe.observableProto.forEach (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2034:19)
WithLatestFromObservable.subscribeCore (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:4084:33)
WithLatestFromObservable.tryCatcher (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:63:31)
setDisposable [as action] (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2082:46)
ScheduledItem.invokeCore (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:896:33)
ScheduledItem.invoke (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:884:40)
runTrampoline (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:1125:37)
tryCatcher (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:63:31)
CurrentThreadScheduler.schedule (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:1141:45)
WithLatestFromObservable.Rx.ObservableBase.ObservableBase._subscribe (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2095:32)
WithLatestFromObservable.Rx.Observable.observableProto.subscribeOnNext (/home/ryan/code/redurx/node_modules/rx/dist/rx.js:2046:19)
If I pass a trivial error handler like () => null to subscribe I don't get the error. Any ideas?
Ryan Lynch
Software Engineer @ Squarespace
I figured it out with some help on StackOverflow; I'll post the answer here as well:
Thanks to user3743222 I figured it out. It turns out (logically actually) that you can't subscribe to a plain observable. It needs to be constructed in a way such that it has values to observe. I changed the initialization for
otherObservablein my unit tests fromnew Rx.Observable()toRx.Observable.just(1), and now it can be subscribed to. I'm a little confused though why it didn't throw the same error when I passed both anonNextandonErrorhandler. But I'll take it.