Back to Rxjs

This is RxJS v 4. Find the latest version here

doc/api/disposables/serialdisposable.md

4.1.04.4 KB
Original Source

This is RxJS v 4. Find the latest version here

Rx.SerialDisposable class

Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.

Usage

The follow example shows the basic usage of an Rx.SerialDisposable.

js
var serialDisposable = new Rx.SerialDisposable();

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

serialDisposable.setDisposable(d1);

var d2 = Rx.Disposable.create(function () {
     console.log('two');
});

serialDisposable.setDisposable(d2);
// => one

serialDisposable.dispose();
// = two

Location

  • rx.js

SerialDisposable Constructor

SerialDisposable Instance Methods

SerialDisposable Instance Properties

SerialDisposable Constructor

<a id="rxserialdisposable"></a>Rx.SerialDisposable()

<a href="#rxserialdisposable">#</a>

Initializes a new instance of the Rx.SerialDisposable class.

Example

js
var serialDisposable = new Rx.SerialDisposable();

console.log(serialDisposable.isDisposed);
// => false

Location

  • rx.js

SerialDisposable Instance Methods

<a id="rxserialdisposableprototypedispose"></a>Rx.SerialDisposable.prototype.dispose()

<a href="#rxserialdisposableprototypedispose">#</a>

Disposes the underlying disposable as well as all future replacements.

Example

js
var serialDisposable = new Rx.SerialDisposable();

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

serialDisposable.setDisposable(disposable);

serialDisposable.dispose();
// => one

var d2 = Rx.Disposable.create(function () {
     console.log('two');
});

// => two

Location

  • rx.js

<a id="rxserialdisposableprototypegetdisposable"></a>Rx.SerialDisposable.prototype.getDisposable()

<a href="#rxserialdisposableprototypegetdisposable">#</a>

Gets the underlying disposable.

Returns

(Disposable): The underlying disposable.

Example

js
var serialDisposable = new Rx.SerialDisposable();

var disposable = Rx.Disposable.create(function () {
     console.log('disposed');
});

serialDisposable.setDisposable(disposable);

var d = serialDisposable.getDisposable();

console.log(d === disposable);

Location

  • rx.js

<a id="rxserialdisposableprototypesetdisposablevalue"></a>Rx.SerialDisposable.prototype.setDisposable(value)

<a href="#rxserialdisposableprototypesetdisposablevalue">#</a>

Sets the underlying disposable.

Arguments

  1. value (Disposable): The new underlying disposable.

Example

js
var serialDisposable = new Rx.SerialDisposable();

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

serialDisposable.setDisposable(d1);

serialDisposable.dispose();
// => one

var d2 = Rx.Disposable.create(function () {
     console.log('two');
});

serialDisposable.setDisposable(d2);
// => two

Location

  • rx.js

SerialDisposable Instance Properties

<a id="isdisposed"></a>isDisposed

<a href="#isdisposed">#</a>

Gets a value that indicates whether the object is disposed.

Example

js
var serialDisposable = new Rx.SerialDisposable();

var disposable = Rx.Disposable.create(function () {
     console.log('disposed');
});

serialDisposable.setDisposable(disposable);

console.log(serialDisposable.isDisposed);
// => false

serialDisposable.dispose();
// => disposed

console.log(serialDisposable.isDisposed);
// => true

Location

  • rx.js