es6/operator/repeat.js
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,
* on a particular Scheduler.
*
* <img src="./img/repeat.png" width="100%">
*
* @param {Scheduler} [scheduler] the Scheduler to emit the items on.
* @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; }
if (count === 0) {
return new EmptyObservable();
}
else if (count < 0) {
return this.lift(new RepeatOperator(-1, this));
}
else {
return this.lift(new RepeatOperator(count - 1, this));
}
}
var RepeatOperator = (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 = (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;
}
this.unsubscribe();
this.isStopped = false;
this.closed = false;
source.subscribe(this);
}
};
return RepeatSubscriber;
}(Subscriber));
//# sourceMappingURL=repeat.js.map