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

defaultIfEmpty.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 defaultIfEmpty(defaultValue) {
  18. if (defaultValue === void 0) { defaultValue = null; }
  19. return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
  20. }
  21. exports.defaultIfEmpty = defaultIfEmpty;
  22. var DefaultIfEmptyOperator = (function () {
  23. function DefaultIfEmptyOperator(defaultValue) {
  24. this.defaultValue = defaultValue;
  25. }
  26. DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
  27. return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
  28. };
  29. return DefaultIfEmptyOperator;
  30. }());
  31. var DefaultIfEmptySubscriber = (function (_super) {
  32. __extends(DefaultIfEmptySubscriber, _super);
  33. function DefaultIfEmptySubscriber(destination, defaultValue) {
  34. var _this = _super.call(this, destination) || this;
  35. _this.defaultValue = defaultValue;
  36. _this.isEmpty = true;
  37. return _this;
  38. }
  39. DefaultIfEmptySubscriber.prototype._next = function (value) {
  40. this.isEmpty = false;
  41. this.destination.next(value);
  42. };
  43. DefaultIfEmptySubscriber.prototype._complete = function () {
  44. if (this.isEmpty) {
  45. this.destination.next(this.defaultValue);
  46. }
  47. this.destination.complete();
  48. };
  49. return DefaultIfEmptySubscriber;
  50. }(Subscriber_1.Subscriber));
  51. //# sourceMappingURL=defaultIfEmpty.js.map