Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Observable.create and Observable.createWithDisposable

Tags:

rxjs

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.

like image 788
Reb.Cabin Avatar asked Oct 20 '25 16:10

Reb.Cabin


1 Answers

[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>
like image 61
Gajus Avatar answered Oct 25 '25 12:10

Gajus