Rx.CompositeDisposable
class
Represents a group of disposable resources that are disposed together.
Usage
The follow example shows the basic usage of an Rx.CompositeDisposable.
var d1 = Rx.Disposable.create(() => console.log('one'));
var d2 = Rx.Disposable.create(() => console.log('two'));
// Initialize with two disposables
var disposables = new Rx.CompositeDisposable(d1, d2);
disposables.dispose();
// => one
// => two
Location
- rx.js
CompositeDisposable Constructor
CompositeDisposable Instance Methods
CompositeDisposable Instance Properties
CompositeDisposable Constructor
Rx.CompositeDisposable(...args)
Initializes a new instance of the Rx.CompositeDisposable
class from a group of disposables.
Arguments
args
(Array|arguments): Disposables that will be disposed together.
Example
var d1 = Rx.Disposable.create(() => console.log('one'));
var d2 = Rx.Disposable.create(() => console.log('two'));
// Initialize with two disposables
var disposables = new Rx.CompositeDisposable(d1, d2);
disposables.dispose();
// => one
// => two
Location
- rx.js
CompositeDisposable Instance Methods
Rx.CompositeDisposable.prototype.add(item)
Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
Arguments
item
(Disposable): Disposable to add.
Example
var disposables = new Rx.CompositeDisposable();
var d1 = Rx.Disposable.create(() => console.log('one'));
disposables.add(d1);
disposables.dispose();
// => one
Location
- rx.js
Rx.CompositeDisposable.prototype.clear()
Removes and disposes all disposables from the CompositeDisposable, but does not dispose the CompositeDisposable.
Example
var d1 = Rx.Disposable.create(() => console.log('one'));
var disposables = new Rx.CompositeDisposable(d1);
console.log(disposables.length);
// => 1
disposables.clear();
// => one
console.log(disposables.length);
// => 0
Location
- rx.js
Rx.CompositeDisposable.prototype.contains(item)
Determines whether the CompositeDisposable contains a specific disposable.
Arguments
item
(Disposable): Disposable to search for.
Returns
(Boolean): true
if the disposable was found; otherwise, false
.
Example
var disposables = new Rx.CompositeDisposable();
var d1 = Rx.Disposable.create(() => console.log('one'));
disposables.add(d1);
console.log(disposables.contains(d1));
// => true
Location
- rx.js
Rx.CompositeDisposable.prototype.dispose()
Disposes all disposables in the group and removes them from the group.
Example
var d1 = Rx.Disposable.create(() => console.log('one'));
var d2 = Rx.Disposable.create(() => console.log('two'));
var disposables = new Rx.CompositeDisposable(d1, d2);
disposables.dispose();
// => one
// => two
console.log(disposables.length);
// => 0
Location
- rx.js
Rx.CompositeDisposable.prototype.remove(item)
Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
Arguments
item
(Disposable): Disposable to remove.
Returns
(Boolean): true
if the disposable was found and disposed; otherwise, false
.
Example
var disposables = new Rx.CompositeDisposable();
var d1 = Rx.Disposable.create(() => console.log('one'));
disposables.add(d1);
console.log(disposables.remove(d1));
// => true
Location
- rx.js
Rx.CompositeDisposable.prototype.rxcompositedisposableprototypetoarray()
Converts the existing CompositeDisposable to an array of disposables
Returns
(Array): An array of disposable objects.
Example
var d1 = Rx.Disposable.create(() => console.log('one'));
var d2 = Rx.Disposable.create(() => console.log('two'));
var disposables = new Rx.CompositeDisposable(d1, d2);
var array = disposables.toArray();
console.log(array.length);
// => 2
Location
- rx.js
CompositeDisposable Instance Properties
isDisposed
Gets a value that indicates whether the object is disposed.
Example
var disposables = new Rx.CompositeDisposable();
var d1 = Rx.Disposable.create(() => console.log('disposed'));
disposables.add(d1);
console.log(disposables.isDisposed);
// => false
disposables.dispose();
// => disposed
console.log(disposables.isDisposed);
// => true
Location
- rx.js
length
Gets the number of disposables in the CompositeDisposable.
Example
var disposables = new Rx.CompositeDisposable();
var d1 = Rx.Disposable.create(() => console.log('disposed'));
disposables.add(d1);
console.log(disposables.length);
// => 1
disposables.dispose();
// => disposed
console.log(disposables.length);
// => 0
Location
- rx.js