///
///
///
module Rx {
export interface Observer {
/**
* Creates a notification callback from an observer.
* @returns The action that forwards its input notification to the underlying observer.
*/
toNotifier(): (notification: Notification) => void;
/**
* Hides the identity of an observer.
* @returns An observer that hides the identity of the specified observer.
*/
asObserver(): Observer;
/**
* Checks access to the observer for grammar violations. This includes checking for multiple OnError or OnCompleted calls, as well as reentrancy in any of the observer methods.
* If a violation is detected, an Error is thrown from the offending observer method call.
* @returns An observer that checks callbacks invocations against the observer grammar and, if the checks pass, forwards those to the specified observer.
*/
checked(): CheckedObserver;
/**
* Schedules the invocation of observer methods on the given scheduler.
* @param {Scheduler} scheduler Scheduler to schedule observer messages on.
* @returns {Observer} Observer whose messages are scheduled on the given scheduler.
*/
notifyOn(scheduler: IScheduler): Observer;
}
export interface ObserverStatic {
/**
* Creates an observer from a notification callback.
*
* @static
* @memberOf Observer
* @param {Function} handler Action that handles a notification.
* @returns The observer object that invokes the specified handler using a notification corresponding to each message it receives.
*/
fromNotifier(handler: (notification: Notification, thisArg?: any) => void): Observer;
}
}
(function() {
var observer: Rx.Observer;
var n: (notification: Rx.Notification) => void = observer.toNotifier();
var o: Rx.Observer = observer.asObserver();
var c: Rx.CheckedObserver = observer.checked();
o = observer.notifyOn(Rx.Scheduler.immediate);
var so : Rx.Observer = Rx.Observer.fromNotifier((n) => {
// Handle next calls
if (n.kind === 'N') {
console.log('Next: ' + n.value);
}
// Handle error calls
if (n.kind === 'E') {
console.log('Error: ' + n.exception);
}
// Handle completed
if (n.kind === 'C') {
console.log('Completed')
}
});
});