CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rx

Library for composing asynchronous and event-based operations in JavaScript using Observable sequences and fluent query operators

Pending
Overview
Eval results
Files

disposables.mddocs/

Disposables

Resource management objects for cleaning up subscriptions and managing the lifetime of observables and observers.

Capabilities

Disposable

Basic disposable interface for resource cleanup.

/**
 * Creates a disposable with the given cleanup action
 * @param {function} action - Action to run during disposal
 * @returns {Disposable} Disposable object
 */
Rx.Disposable.create = function(action);

/**
 * Gets an empty disposable that does nothing when disposed
 * @returns {Disposable} Empty disposable
 */
Rx.Disposable.empty;

/**
 * Checks if object is a disposable
 * @param {*} obj - Object to test
 * @returns {boolean} True if object is disposable
 */
Rx.Disposable.isDisposable = function(obj);

/**
 * Disposes the resource
 */
dispose: function();

/**
 * Gets a value that indicates whether the object is disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

Usage Example:

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

// Later...
disposable.dispose(); // Logs: 'Cleanup performed'
console.log(disposable.isDisposed()); // true

CompositeDisposable

Manages multiple disposables as a single disposable.

/**
 * Creates a composite disposable with initial disposables
 * @param {...Disposable} disposables - Initial disposables to manage
 * @returns {CompositeDisposable} Composite disposable
 */
function CompositeDisposable(...disposables);

/**
 * Adds a disposable to the group
 * @param {Disposable} item - Disposable to add
 */
add: function(item);

/**
 * Removes and disposes a disposable from the group
 * @param {Disposable} item - Disposable to remove
 * @returns {boolean} True if item was found and removed
 */
remove: function(item);

/**
 * Disposes all disposables in the group and prohibits adding more
 */
dispose: function();

/**
 * Clears all disposables from group without disposing them
 */
clear: function();

/**
 * Converts to array of disposables
 * @returns {Array<Disposable>} Array of disposables
 */
toArray: function();

/**
 * Gets the number of disposables in the group
 * @returns {number} Count of disposables
 */
length: number;

/**
 * Gets whether the group is disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

Usage Example:

var composite = new Rx.CompositeDisposable();

var subscription1 = someObservable.subscribe(observer1);
var subscription2 = someObservable.subscribe(observer2);

composite.add(subscription1);
composite.add(subscription2);

// Dispose all subscriptions at once
composite.dispose();

SerialDisposable

Holds a single disposable, replacing it with new ones over time.

/**
 * Creates a serial disposable
 * @returns {SerialDisposable} Serial disposable
 */
function SerialDisposable();

/**
 * Gets or sets the current disposable
 * @param {Disposable} [value] - New disposable to set
 * @returns {Disposable} Current disposable if getting
 */
getDisposable: function();
setDisposable: function(value);

/**
 * Disposes the current disposable and prevents future assignments
 */
dispose: function();

/**
 * Gets whether the serial disposable is disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

Usage Example:

var serialDisposable = new Rx.SerialDisposable();

// Set initial subscription
serialDisposable.setDisposable(observable1.subscribe(observer));

// Replace with new subscription (previous one is disposed)
serialDisposable.setDisposable(observable2.subscribe(observer));

// Dispose current subscription
serialDisposable.dispose();

SingleAssignmentDisposable

Holds a single disposable that can only be assigned once.

/**
 * Creates a single assignment disposable
 * @returns {SingleAssignmentDisposable} Single assignment disposable
 */
function SingleAssignmentDisposable();

/**
 * Gets the current disposable
 * @returns {Disposable} Current disposable
 */
getDisposable: function();

/**
 * Sets the disposable (can only be called once)
 * @param {Disposable} value - Disposable to set
 */
setDisposable: function(value);

/**
 * Disposes the current disposable
 */
dispose: function();

/**
 * Gets whether the disposable is disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

RefCountDisposable

Provides a disposable that can be disposed multiple times with reference counting.

/**
 * Creates a reference counted disposable
 * @param {Disposable} disposable - Underlying disposable to manage
 * @returns {RefCountDisposable} Reference counted disposable
 */
function RefCountDisposable(disposable);

/**
 * Disposes the underlying disposable
 */
dispose: function();

/**
 * Gets whether the disposable is disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

/**
 * Returns a disposable that increments the reference count
 * @returns {Disposable} Disposable that decrements count when disposed
 */
getDisposable: function();

BinaryDisposable

Manages two disposables as a single disposable.

/**
 * Creates a binary disposable
 * @param {Disposable} first - First disposable
 * @param {Disposable} second - Second disposable
 * @returns {BinaryDisposable} Binary disposable
 */
function BinaryDisposable(first, second);

/**
 * Disposes both disposables
 */
dispose: function();

/**
 * Gets whether both disposables are disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

ScheduledDisposable

Schedules disposal of another disposable on a specific scheduler.

/**
 * Creates a scheduled disposable
 * @param {Scheduler} scheduler - Scheduler to dispose on
 * @param {Disposable} disposable - Disposable to schedule for disposal
 * @returns {ScheduledDisposable} Scheduled disposable
 */
function ScheduledDisposable(scheduler, disposable);

/**
 * Schedules disposal of the wrapped disposable
 */
dispose: function();

/**
 * Gets whether the disposable is disposed
 * @returns {boolean} True if disposed
 */
isDisposed: function();

Types

// Core disposable interface
interface Disposable {
  dispose(): void;
  isDisposed(): boolean;
}

// Composite disposable interface
interface CompositeDisposable extends Disposable {
  add(item: Disposable): void;
  remove(item: Disposable): boolean;
  clear(): void;
  toArray(): Disposable[];
  length: number;
}

// Serial disposable interface
interface SerialDisposable extends Disposable {
  getDisposable(): Disposable;
  setDisposable(value: Disposable): void;
}

// Single assignment disposable interface
interface SingleAssignmentDisposable extends Disposable {
  getDisposable(): Disposable;
  setDisposable(value: Disposable): void;
}

// Reference counted disposable interface
interface RefCountDisposable extends Disposable {
  getDisposable(): Disposable;
}

Install with Tessl CLI

npx tessl i tessl/npm-rx

docs

async-operations.md

disposables.md

index.md

observable-aggregation.md

observable-combination.md

observable-creation.md

observable-filtering.md

observable-transformation.md

schedulers.md

subjects.md

testing.md

time-operations.md

tile.json