Tumortisch-Dist/resources/app/node_modules/rxjs/operators/mapTo.js

63 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2021-06-15 16:00:08 +02:00
"use strict";
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 __());
};
var Subscriber_1 = require('../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
*/
function mapTo(value) {
return function (source) { return source.lift(new MapToOperator(value)); };
}
exports.mapTo = mapTo;
var MapToOperator = (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 = (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_1.Subscriber));
//# sourceMappingURL=mapTo.js.map