import {Operator} from '../Operator';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {Notification} from '../Notification';
/**
* Returns an Observable that represents all of the emissions and notifications
* from the source Observable into emissions marked with their original types
* within a `Notification` objects.
*
*
*
* @see {@link Notification}
*
* @scheduler materialize does not operate by default on a particular Scheduler.
* @return {Observable>} an Observable that emits items that are the result of
* materializing the items and notifications of the source Observable.
* @method materialize
* @owner Observable
*/
export function materialize(): Observable> {
return this.lift(new MaterializeOperator());
}
export interface MaterializeSignature {
(): Observable>;
}
class MaterializeOperator implements Operator> {
call(subscriber: Subscriber>, source: any): any {
return source._subscribe(new MaterializeSubscriber(subscriber));
}
}
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class MaterializeSubscriber extends Subscriber {
constructor(destination: Subscriber>) {
super(destination);
}
protected _next(value: T) {
this.destination.next(Notification.createNext(value));
}
protected _error(err: any) {
const destination = this.destination;
destination.next(Notification.createError(err));
destination.complete();
}
protected _complete() {
const destination = this.destination;
destination.next(Notification.createComplete());
destination.complete();
}
}