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