Rx.Subject

Represents an object that is both an observable sequence as well as an observer. Each notification is broadcasted to all subscribed observers.

This class inherits both from the Rx.Observable and Rx.Observer classes.

Usage ##

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

var subject = new Rx.Subject();

var subscription = subject.subscribe(
    function (x) {
        console.log('Next: ' + x.toString());
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

subject.onNext(42);

// => Next: 42

subject.onNext(56);

// => Next: 56

subject.onCompleted();

// => Completed

Location

  • rx.js

Subject Constructor ##

Subject Class Methods ##

Subject Instance Methods ##

Inherited Classes ##

Subject Constructor ##

Rx.Subject()

#

Creates a subject.

Example

Location

  • rx.js

Subject Class Methods ##

Rx.Subject.create(observer, observable)

#

Creates a subject from the specified observer and observable.

Arguments

  1. observer (Observer): The observer used to send messages to the subject.

  2. observable (Observable): The observable used to subscribe to messages sent from the subject.

Returns

(Subject): Subject implemented using the given observer and observable.

Example

Location

  • rx.js

Subject Instance Methods ##

Rx.Subject.prototype.dispose()

#

Unsubscribe all observers and release resources.

Example

Location

  • rx.js

Rx.Subject.prototype.hasObservers()

#

Indicates whether the subject has observers subscribed to it.

Returns

(Boolean): Returns true if the Subject has observers, else false.

Example

Location

  • rx.js

Last updated

Was this helpful?