biofriction-wp-theme/node_modules/rxjs/_esm5/operators/repeat.js

76 lines
2.5 KiB
JavaScript

/** PURE_IMPORTS_START .._Subscriber,.._observable_EmptyObservable 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';
import { EmptyObservable } from '../observable/EmptyObservable';
/**
* Returns an Observable that repeats the stream of items emitted by the source Observable at most count times.
*
* <img src="./img/repeat.png" width="100%">
*
* @param {number} [count] The number of times the source Observable items are repeated, a count of 0 will yield
* an empty Observable.
* @return {Observable} An Observable that repeats the stream of items emitted by the source Observable at most
* count times.
* @method repeat
* @owner Observable
*/
export function repeat(count) {
if (count === void 0) {
count = -1;
}
return function (source) {
if (count === 0) {
return new EmptyObservable();
}
else if (count < 0) {
return source.lift(new RepeatOperator(-1, source));
}
else {
return source.lift(new RepeatOperator(count - 1, source));
}
};
}
var RepeatOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
function RepeatOperator(count, source) {
this.count = count;
this.source = source;
}
RepeatOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
};
return RepeatOperator;
}());
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
var RepeatSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
__extends(RepeatSubscriber, _super);
function RepeatSubscriber(destination, count, source) {
_super.call(this, destination);
this.count = count;
this.source = source;
}
RepeatSubscriber.prototype.complete = function () {
if (!this.isStopped) {
var _a = this, source = _a.source, count = _a.count;
if (count === 0) {
return _super.prototype.complete.call(this);
}
else if (count > -1) {
this.count = count - 1;
}
source.subscribe(this._unsubscribeAndRecycle());
}
};
return RepeatSubscriber;
}(Subscriber));
//# sourceMappingURL=repeat.js.map