Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.48k stars 2.1k forks source link

subscription.add is not a function #1464

Closed mrdulin closed 7 years ago

mrdulin commented 7 years ago

"rx": "^4.1.0",

I follow the official doc, I want to unsubscribe two subscription, but it give me an error.

subscription.add(childSubscription);
             ^

TypeError: subscription.add is not a function

Here is my code snippet:

const Rx = require('rx');

const obs1 = Rx.Observable.interval(1000);
const obs2 = Rx.Observable.interval(1000);

const subscription = obs1.subscribe(x => console.log(x));
const childSubscription = obs2.subscribe(x => console.log(x));

subscription.add(childSubscription);

setTimeout(() => {
  subscription.dispose();
}, 2000);

I am so confused about the official doc.

paulpdaniels commented 7 years ago

See my answer to your other question. You are referencing docs for v5 and above. For v4 you need to use a CompositeDisposable to group Disposables together.

mrdulin commented 7 years ago

@paulpdaniels Thanks. I am clear!