Reputation: 5567
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
Reputation: 73888
[create] is an alias for the
createWithDisposable
method.
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
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