frontend/.pnpm-store/v3/files/e7/5773f6932b3ed37b69427e58056006863ae2fc68cf9b07a9a70a56f1f79af415f83224178756b1b92a0b573a857e87834cbd5b5542f274b4aa28602ba1b382

43 lines
1.1 KiB
Plaintext

import { Subscriber } from '../Subscriber';
import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
import { empty } from '../observable/empty';
export function take(count) {
return (source) => {
if (count === 0) {
return empty();
}
else {
return source.lift(new TakeOperator(count));
}
};
}
class TakeOperator {
constructor(total) {
this.total = total;
if (this.total < 0) {
throw new ArgumentOutOfRangeError;
}
}
call(subscriber, source) {
return source.subscribe(new TakeSubscriber(subscriber, this.total));
}
}
class TakeSubscriber extends Subscriber {
constructor(destination, total) {
super(destination);
this.total = total;
this.count = 0;
}
_next(value) {
const total = this.total;
const count = ++this.count;
if (count <= total) {
this.destination.next(value);
if (count === total) {
this.destination.complete();
this.unsubscribe();
}
}
}
}
//# sourceMappingURL=take.js.map