Reb.Cabin
Reb.Cabin

Reputation: 5567

Difference between Observable.create and Observable.createWithDisposable

What is the difference between Observable.create and Observable.createWithDisposable? I can't see the difference from the documentation or by looking at the source code.

Upvotes: 4

Views: 1222

Answers (2)

Gajus
Gajus

Reputation: 73888

[create] is an alias for the createWithDisposable method.

https://github.com/Reactive-Extensions/RxJS/blob/d94905a34ba9953e705975acce136c0d0dbd495e/doc/api/core/operators/create.md

The two functions are interchangeable. createWithDisposable has been deprecated. You should use create.

create function can return a function that will be called when subscription is disposed (this function must be used to clean up).

var source,
    subscription;

source = Rx.Observable.create(function (observer) {
    // ..

    return function () {
        console.log('disposed');
    };
});

subscription = source.subscribe();

subscription.dispose();
<script src='https://rawgit.com/Reactive-Extensions/RxJS/v.2.5.3/dist/rx.all.js'></script>

Upvotes: 2

Reb.Cabin
Reb.Cabin

Reputation: 5567

Looks like createWithDisposable wraps the user-supplied subscribe function with a subscribe that returns a default disposable, whereas create requires the user-supplied subscribe function explicitly to return a disposable.

Upvotes: 1

Related Questions