Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

readme.md

Rx.js v2.1.8

Observable object

The Observable object represents a push based collection.

The Observer and Objects interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The Observable object represents the object that sends notifications (the provider); the Observer object represents the class that receives them (the observer).

Observable Methods

Observable Instance Methods

Rx.Observable.amb

# [Ⓣ][1]

Propagates the observable sequence that reacts first.

Arguments

  1. array (Array|arguments): Observable sources competing to react first either as an array or arguments.

Returns

(Observable): An observable sequence that surfaces any of the given sequences, whichever reacted first.

Example

var obs = Rx.Observable.amb(
	Rx.Observable.timer(500).select(function () { return 'foo'; }),
	Rx.Observable.timer(200).select(function () { return 'bar'; })
);

obs.subscribe( function (x) {
	console.log(x);
});

// => 'bar'

Rx.Observable.catchException

# [Ⓣ][1]

Continues an observable sequence that is terminated by an exception with the next observable sequence.

Arguments

  1. array (Array|arguments): Observable sequences to catch exceptions for.

Returns

(Observable): An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.

Example

var obs1 = Rx.Observable.throwException(new Error('error'));
var obs2 = Rx.Observable.returnValue(42);

var obs3 = Rx.Observable.catchException(obs1, obs2);

obs3.subscribe( function (x) {
    console.log(x);
});

// => 42

Rx.Observable.concat

# [Ⓣ][1]

Concatenates all of the specified observable sequences, as long as the previous observable sequence terminated successfully.

Arguments

  1. array (Array|arguments): Observable sequences to concatenate.

Returns

(Observable): An observable sequence that contains the elements of each given sequence, in sequential order.

Example

var source1 = Rx.Observable.returnValue(42);
var source2 = Rx.Observable.returnValue(56);

var obs = Rx.Observable.concat(source1, source2);

obs.subscribe( function (x) {
	console.log(x);
});

// => 42
// => 56

Rx.Observable.create

# [Ⓣ][1]

Creates an observable sequence from a specified subscribe method implementation.

Arguments

  1. subscribe (Function): Implementation of the resulting observable sequence's subscribe method, optionally returning a function that will be wrapped in a disposable object.

Returns

(Observable): The observable sequence with the specified implementation for the subscribe method.

Example

var source = Rx.Observable.create(function (observer) {
	observer.onNext(42);
	observer.onCompleted();

	// Note that this is optional, you do not have to return this if you require no cleanup
	return function () {
		console.log('disposed');
	};
});

var subscription = source.subscribe(function (x) {
	console.log(x);
});

// => 42

subscription.dispose();

// => disposed

Rx.Observable.createWithDisposable

# [Ⓣ][1]

Creates an observable sequence from a specified Subscribe method implementation.

Arguments

  1. subscribe (Function): Implementation of the resulting observable sequence's subscribe method.

Returns

(Observable): The observable sequence with the specified implementation for the subscribe method.

Example

var source = Rx.Observable.createWithDisposable(function (observer) {
	observer.onNext(42);
	observer.onCompleted();

	return Rx.Disposable.create(function () {
		// Any cleanup that is required
		console.log('disposed');
	});
});

var subscription = source.subscribe(function (x) {
	console.log(x);
});

// => 42

subscription.dispose();

// => disposed

Rx.Observable.defer

# [Ⓣ][1]

Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.

Arguments

  1. observableFactory (Function): Observable factory function to invoke for each observer that subscribes to the resulting sequence.

Returns

(Observable): An observable sequence whose observers trigger an invocation of the given observable factory function.

Example

var source = Rx.Observable.defer(function () {
	return Rx.Observable.returnValue(42);
});

var subscription = source.subscribe(function (x) {
	console.log(x);
});

// => 42