-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Mastering Reactive JavaScript
By :
The Disposable class gives us a method to release allocated resources (database connections, file handlers, and so on). We can do this by calling the dispose() method of this object.
In this section, we will use the dispose() method to unsubscribe from an observable.
To create a Disposable, we can use the create() function from Rx.Disposable:
var disposable = Rx.Disposable
.create(()=>console.log('Releasing allocated resources'));
disposable.dispose(); If you run this code, it will print the following message in your console:
Releasing allocated resourcesAs discussed earlier in this chapter, we can call the dispose() method to unsubscribe from an observable. In some cases, we can even define a Disposable to be used when someone calls the dispose() method from this observable (remember the create() and createWithDisposable() functions to create an observable).
The Disposable class also gives us functions to control groups of Disposable objects. The two most important...