doc/api/disposables/compositedisposable.md
Rx.CompositeDisposable classRepresents 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
CompositeDisposable ConstructorCompositeDisposable Instance MethodsCompositeDisposable Instance PropertiesRx.CompositeDisposable(...args)<a href="#rxcompositedisposablergs">#</a> Ⓢ
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.CompositeDisposable.prototype.add(item)<a href="#rxcompositedisposableprototypeadditem">#</a> Ⓢ
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.CompositeDisposable.prototype.dispose()<a href="#rxcompositedisposableprototypedispose">#</a> Ⓢ
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.CompositeDisposable.prototype.remove(item)<a href="#rxcompositedisposableprototyperemoveitem">#</a> Ⓢ
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.CompositeDisposable.prototype.toarray()<a href="#rxcompositedisposableprototypetoarray">#</a> Ⓢ
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
isDisposed<a href="#isdisposed">#</a> Ⓢ
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
length<a href="#length">#</a> Ⓢ
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