Skip to content

Latest commit

 

History

History
268 lines (175 loc) · 5.97 KB

compositedisposable.md

File metadata and controls

268 lines (175 loc) · 5.97 KB

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(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

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

  1. args (Array|arguments): Disposables that will be disposed together.

Example

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

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

  1. item (Disposable): Disposable to add.

Example

var disposables = new Rx.CompositeDisposable();

var d1 = Rx.Disposable.create(function () {
     console.log('one');
});

disposables.add(d1);

disposables.dispose();
// => one

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(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

Location

  • rx.js

Rx.CompositeDisposable.prototype.remove(item)

#

Removes and disposes the first occurrence of a disposable from the CompositeDisposable.

Arguments

  1. 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(function () {
     console.log('one');
});

disposables.add(d1);

console.log(disposables.remove(d1));
// => true

Location

  • rx.js

Rx.CompositeDisposable.prototype.toarray()

#

Converts the existing CompositeDisposable to an array of disposables. Does not dispose the objects.

Returns

(Array): An array of disposable objects.

Example

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

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(function () {
     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(function () {
     console.log('disposed');
});

disposables.add(d1);

console.log(disposables.length);
// => 1

disposables.dispose();
// => disposed

console.log(disposables.length);
// => 0

Location

  • rx.js