Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

take.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var Subscriber_1 = require("../Subscriber");
  17. var ArgumentOutOfRangeError_1 = require("../util/ArgumentOutOfRangeError");
  18. var empty_1 = require("../observable/empty");
  19. function take(count) {
  20. return function (source) {
  21. if (count === 0) {
  22. return empty_1.empty();
  23. }
  24. else {
  25. return source.lift(new TakeOperator(count));
  26. }
  27. };
  28. }
  29. exports.take = take;
  30. var TakeOperator = (function () {
  31. function TakeOperator(total) {
  32. this.total = total;
  33. if (this.total < 0) {
  34. throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError;
  35. }
  36. }
  37. TakeOperator.prototype.call = function (subscriber, source) {
  38. return source.subscribe(new TakeSubscriber(subscriber, this.total));
  39. };
  40. return TakeOperator;
  41. }());
  42. var TakeSubscriber = (function (_super) {
  43. __extends(TakeSubscriber, _super);
  44. function TakeSubscriber(destination, total) {
  45. var _this = _super.call(this, destination) || this;
  46. _this.total = total;
  47. _this.count = 0;
  48. return _this;
  49. }
  50. TakeSubscriber.prototype._next = function (value) {
  51. var total = this.total;
  52. var count = ++this.count;
  53. if (count <= total) {
  54. this.destination.next(value);
  55. if (count === total) {
  56. this.destination.complete();
  57. this.unsubscribe();
  58. }
  59. }
  60. };
  61. return TakeSubscriber;
  62. }(Subscriber_1.Subscriber));
  63. //# sourceMappingURL=take.js.map