blob: 879122be9e687a737841aa1b77274b8f8bfe0781 [file] [log] [blame]
/** PURE_IMPORTS_START tslib,_Subscriber,_util_ArgumentOutOfRangeError,_observable_empty PURE_IMPORTS_END */
import * as tslib_1 from "tslib";
import { Subscriber } from '../Subscriber';
import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
import { empty } from '../observable/empty';
export function take(count) {
return function (source) {
if (count === 0) {
return empty();
}
else {
return source.lift(new TakeOperator(count));
}
};
}
var TakeOperator = /*@__PURE__*/ (function () {
function TakeOperator(total) {
this.total = total;
if (this.total < 0) {
throw new ArgumentOutOfRangeError;
}
}
TakeOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new TakeSubscriber(subscriber, this.total));
};
return TakeOperator;
}());
var TakeSubscriber = /*@__PURE__*/ (function (_super) {
tslib_1.__extends(TakeSubscriber, _super);
function TakeSubscriber(destination, total) {
var _this = _super.call(this, destination) || this;
_this.total = total;
_this.count = 0;
return _this;
}
TakeSubscriber.prototype._next = function (value) {
var total = this.total;
var count = ++this.count;
if (count <= total) {
this.destination.next(value);
if (count === total) {
this.destination.complete();
this.unsubscribe();
}
}
};
return TakeSubscriber;
}(Subscriber));
//# sourceMappingURL=take.js.map