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

find.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 find(predicate, thisArg) {
  18. if (typeof predicate !== 'function') {
  19. throw new TypeError('predicate is not a function');
  20. }
  21. return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
  22. }
  23. exports.find = find;
  24. var FindValueOperator = (function () {
  25. function FindValueOperator(predicate, source, yieldIndex, thisArg) {
  26. this.predicate = predicate;
  27. this.source = source;
  28. this.yieldIndex = yieldIndex;
  29. this.thisArg = thisArg;
  30. }
  31. FindValueOperator.prototype.call = function (observer, source) {
  32. return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
  33. };
  34. return FindValueOperator;
  35. }());
  36. exports.FindValueOperator = FindValueOperator;
  37. var FindValueSubscriber = (function (_super) {
  38. __extends(FindValueSubscriber, _super);
  39. function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
  40. var _this = _super.call(this, destination) || this;
  41. _this.predicate = predicate;
  42. _this.source = source;
  43. _this.yieldIndex = yieldIndex;
  44. _this.thisArg = thisArg;
  45. _this.index = 0;
  46. return _this;
  47. }
  48. FindValueSubscriber.prototype.notifyComplete = function (value) {
  49. var destination = this.destination;
  50. destination.next(value);
  51. destination.complete();
  52. this.unsubscribe();
  53. };
  54. FindValueSubscriber.prototype._next = function (value) {
  55. var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
  56. var index = this.index++;
  57. try {
  58. var result = predicate.call(thisArg || this, value, index, this.source);
  59. if (result) {
  60. this.notifyComplete(this.yieldIndex ? index : value);
  61. }
  62. }
  63. catch (err) {
  64. this.destination.error(err);
  65. }
  66. };
  67. FindValueSubscriber.prototype._complete = function () {
  68. this.notifyComplete(this.yieldIndex ? -1 : undefined);
  69. };
  70. return FindValueSubscriber;
  71. }(Subscriber_1.Subscriber));
  72. exports.FindValueSubscriber = FindValueSubscriber;
  73. //# sourceMappingURL=find.js.map