This is RxJS v 4. Find the latest version here
Represents a notification to an observer.
This can be dematerialized into an Observable.
var source = Rx.Observable
.of(
Rx.Notification.createOnNext(42),
Rx.Notification.createOnCompleted()
)
.dematerialize();
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
File:
Creates an object that represents an OnCompleted notification to an observer.
Notification
- The OnCompleted notification.
var source = Rx.Observable
.of(Rx.Notification.createOnCompleted() )
.dematerialize();
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Completed
Creates an object that represents an OnError notification to an observer.
error
:Any
- The exception contained in the notification.
Notification
- The OnError notification containing the exception.
var source = Rx.Observable
.of(Rx.Notification.createOnError(new Error('woops')) )
.dematerialize();
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Error: Error: woops
- rx.js
Creates an object that represents an OnNext notification to an observer.
value
:Any
- The value contained in the notification.
Notification
: The onNext notification containing the value.
var source = Rx.Observable
.of(
Rx.Notification.createOnNext(42),
Rx.Notification.createOnCompleted()
)
.dematerialize();
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result or the individual functions given.
[observer]
:Observer
Observer to invoke the notification on.
OR
onNext
:Function
- Function to invoke for anonNext
notification.onError
:Function
- Function to invoke for anonError
notification.onCompleted
:Function
- Function to invoke for anonCompleted
notification.
Any
: Result produced by the observation.
/* Using an observer */
var observer = Rx.Observer.create(function (x) { return x; });
var notification = Rx.Notification.createOnNext(42);
console.log(notification.accept(observer));
// => 42
/* Using a function */
var notification = Rx.Notification.createOnNext(42);
console.log(notification.accept(function (x) { return x; }))
// => 42
Returns an observable sequence with a single notification.
[scheduler = Rx.Scheduler.immediate]
Scheduler
: Scheduler to send out the notification calls on.
Observable
: The observable sequence that surfaces the behavior of the notification upon subscription.
/* Without a scheduler */
var source = Rx.Notification.createOnNext(42)
.toObservable();
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
/* With a scheduler */
var source = Rx.Notification.createOnError(new Error('error!'))
.toObservable(Rx.Scheduler.default);
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Error: Error: error!
Gets the exception from the OnError notification.
Any
: The Error from the onError
notification.
var notification = Rx.Notification.createOnError(new Error('invalid'));
console.log(notification.error);
// => Error: invalid
Gets the kind from the notification which denotes 'N' for OnNext, 'E' for OnError and 'C' for OnCompleted.
String
: The kind from the notification which denotes 'N' for OnNext, 'E' for OnError and 'C' for OnCompleted.
var notification = Rx.Notification.createOnCompleted();
console.log(notification.kind);
// => C
Gets the value from the onNext
notification.
Any
: The value from the onNext
notification.
var notification = Rx.Notification.createOnNext(42);
console.log(notification.value);
// => 42