blob: fb86ea495bfbdba72190bb339a33976753156b7c [file] [log] [blame]
/** PURE_IMPORTS_START .._Subscriber PURE_IMPORTS_END */
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
import { Subscriber } from '../Subscriber';
/**
* Emits the given constant value on the output Observable every time the source
* Observable emits a value.
*
* <span class="informal">Like {@link map}, but it maps every source value to
* the same output value every time.</span>
*
* <img src="./img/mapTo.png" width="100%">
*
* Takes a constant `value` as argument, and emits that whenever the source
* Observable emits a value. In other words, ignores the actual source value,
* and simply uses the emission moment to know when to emit the given `value`.
*
* @example <caption>Map every click to the string 'Hi'</caption>
* var clicks = Rx.Observable.fromEvent(document, 'click');
* var greetings = clicks.mapTo('Hi');
* greetings.subscribe(x => console.log(x));
*
* @see {@link map}
*
* @param {any} value The value to map each source value to.
* @return {Observable} An Observable that emits the given `value` every time
* the source Observable emits something.
* @method mapTo
* @owner Observable
*/
export function mapTo(value) {
return function (source) { return source.lift(new MapToOperator(value)); };
}
var MapToOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
function MapToOperator(value) {
this.value = value;
}
MapToOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new MapToSubscriber(subscriber, this.value));
};
return MapToOperator;
}());
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
var MapToSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
__extends(MapToSubscriber, _super);
function MapToSubscriber(destination, value) {
_super.call(this, destination);
this.value = value;
}
MapToSubscriber.prototype._next = function (x) {
this.destination.next(this.value);
};
return MapToSubscriber;
}(Subscriber));
//# sourceMappingURL=mapTo.js.map