Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

takeWhile.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. function takeWhile(predicate, inclusive) {
  18. if (inclusive === void 0) { inclusive = false; }
  19. return function (source) {
  20. return source.lift(new TakeWhileOperator(predicate, inclusive));
  21. };
  22. }
  23. exports.takeWhile = takeWhile;
  24. var TakeWhileOperator = (function () {
  25. function TakeWhileOperator(predicate, inclusive) {
  26. this.predicate = predicate;
  27. this.inclusive = inclusive;
  28. }
  29. TakeWhileOperator.prototype.call = function (subscriber, source) {
  30. return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));
  31. };
  32. return TakeWhileOperator;
  33. }());
  34. var TakeWhileSubscriber = (function (_super) {
  35. __extends(TakeWhileSubscriber, _super);
  36. function TakeWhileSubscriber(destination, predicate, inclusive) {
  37. var _this = _super.call(this, destination) || this;
  38. _this.predicate = predicate;
  39. _this.inclusive = inclusive;
  40. _this.index = 0;
  41. return _this;
  42. }
  43. TakeWhileSubscriber.prototype._next = function (value) {
  44. var destination = this.destination;
  45. var result;
  46. try {
  47. result = this.predicate(value, this.index++);
  48. }
  49. catch (err) {
  50. destination.error(err);
  51. return;
  52. }
  53. this.nextOrComplete(value, result);
  54. };
  55. TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {
  56. var destination = this.destination;
  57. if (Boolean(predicateResult)) {
  58. destination.next(value);
  59. }
  60. else {
  61. if (this.inclusive) {
  62. destination.next(value);
  63. }
  64. destination.complete();
  65. }
  66. };
  67. return TakeWhileSubscriber;
  68. }(Subscriber_1.Subscriber));
  69. //# sourceMappingURL=takeWhile.js.map