exhaust.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
  4. export function exhaust() {
  5. return function (source) { return source.lift(new SwitchFirstOperator()); };
  6. }
  7. var SwitchFirstOperator = /*@__PURE__*/ (function () {
  8. function SwitchFirstOperator() {
  9. }
  10. SwitchFirstOperator.prototype.call = function (subscriber, source) {
  11. return source.subscribe(new SwitchFirstSubscriber(subscriber));
  12. };
  13. return SwitchFirstOperator;
  14. }());
  15. var SwitchFirstSubscriber = /*@__PURE__*/ (function (_super) {
  16. tslib_1.__extends(SwitchFirstSubscriber, _super);
  17. function SwitchFirstSubscriber(destination) {
  18. var _this = _super.call(this, destination) || this;
  19. _this.hasCompleted = false;
  20. _this.hasSubscription = false;
  21. return _this;
  22. }
  23. SwitchFirstSubscriber.prototype._next = function (value) {
  24. if (!this.hasSubscription) {
  25. this.hasSubscription = true;
  26. this.add(innerSubscribe(value, new SimpleInnerSubscriber(this)));
  27. }
  28. };
  29. SwitchFirstSubscriber.prototype._complete = function () {
  30. this.hasCompleted = true;
  31. if (!this.hasSubscription) {
  32. this.destination.complete();
  33. }
  34. };
  35. SwitchFirstSubscriber.prototype.notifyComplete = function () {
  36. this.hasSubscription = false;
  37. if (this.hasCompleted) {
  38. this.destination.complete();
  39. }
  40. };
  41. return SwitchFirstSubscriber;
  42. }(SimpleOuterSubscriber));
  43. //# sourceMappingURL=exhaust.js.map