Back to Rxjs

This is RxJS v 4. Find the latest version here

doc/api/disposables/disposable.md

4.1.07.4 KB
Original Source

This is RxJS v 4. Find the latest version here

Rx.Disposable class

Provides a set of static methods for creating Disposables, which defines a method to release allocated resources.

Usage

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

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

disposable.dispose();
// => disposed

Disposable Class Methods

Disposable Class Properties

Disposable Instance Methods

Class Methods

<a id="rxdisposablecreateaction"></a>Rx.Disposable.create(action)

<a href="#rxdisposablecreateaction">#</a> [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/disposable.js"View in source")

Creates a disposable object that invokes the specified action when disposed.

Arguments

  1. action (Function): Function to run during the first call to dispose. The action is guaranteed to be run at most once.

Returns

(Disposable): The disposable object that runs the given action upon disposal.

Example

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

disposable.dispose();
// => disposed

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests:


<a id="rxdisposableisdisposabled"></a>Rx.Disposable.isDisposable(d)

<a href="#rxdisposableisdisposabled">#</a> [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/disposable.js"View in source")

Creates a disposable object that invokes the specified action when disposed.

Arguments

  1. d (Object): Object to validate whether it has a dispose method.

Returns

(Boolean): true if is a disposable object, else false.

Example

js
var disposable = Rx.Disposable.empty;
console.log(disposable.isDisposable(disposable));
// => true

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests:


Disposable Class Properties

<a id="rxdisposableempty"></a>Rx.Disposable.empty

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

Gets the disposable that does nothing when disposed.

Returns

(Disposable): The disposable that does nothing when disposed.

Example

js
var disposable = Rx.Disposable.empty;

disposable.dispose(); // Does nothing

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests:


Disposable Instance Methods

<a id="rxdisposableprototypedispose"></a>Rx.Disposable.prototype.dispose()

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

Performs the task of cleaning up resources.

Example

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

disposable.dispose();
// => disposed

Location

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests: