skipUntil.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var OuterSubscriber_1 = require('../OuterSubscriber');
  8. var subscribeToResult_1 = require('../util/subscribeToResult');
  9. /**
  10. * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item.
  11. *
  12. * <img src="./img/skipUntil.png" width="100%">
  13. *
  14. * @param {Observable} notifier - The second Observable that has to emit an item before the source Observable's elements begin to
  15. * be mirrored by the resulting Observable.
  16. * @return {Observable<T>} An Observable that skips items from the source Observable until the second Observable emits
  17. * an item, then emits the remaining items.
  18. * @method skipUntil
  19. * @owner Observable
  20. */
  21. function skipUntil(notifier) {
  22. return function (source) { return source.lift(new SkipUntilOperator(notifier)); };
  23. }
  24. exports.skipUntil = skipUntil;
  25. var SkipUntilOperator = (function () {
  26. function SkipUntilOperator(notifier) {
  27. this.notifier = notifier;
  28. }
  29. SkipUntilOperator.prototype.call = function (subscriber, source) {
  30. return source.subscribe(new SkipUntilSubscriber(subscriber, this.notifier));
  31. };
  32. return SkipUntilOperator;
  33. }());
  34. /**
  35. * We need this JSDoc comment for affecting ESDoc.
  36. * @ignore
  37. * @extends {Ignored}
  38. */
  39. var SkipUntilSubscriber = (function (_super) {
  40. __extends(SkipUntilSubscriber, _super);
  41. function SkipUntilSubscriber(destination, notifier) {
  42. _super.call(this, destination);
  43. this.hasValue = false;
  44. this.isInnerStopped = false;
  45. this.add(subscribeToResult_1.subscribeToResult(this, notifier));
  46. }
  47. SkipUntilSubscriber.prototype._next = function (value) {
  48. if (this.hasValue) {
  49. _super.prototype._next.call(this, value);
  50. }
  51. };
  52. SkipUntilSubscriber.prototype._complete = function () {
  53. if (this.isInnerStopped) {
  54. _super.prototype._complete.call(this);
  55. }
  56. else {
  57. this.unsubscribe();
  58. }
  59. };
  60. SkipUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  61. this.hasValue = true;
  62. };
  63. SkipUntilSubscriber.prototype.notifyComplete = function () {
  64. this.isInnerStopped = true;
  65. if (this.isStopped) {
  66. _super.prototype._complete.call(this);
  67. }
  68. };
  69. return SkipUntilSubscriber;
  70. }(OuterSubscriber_1.OuterSubscriber));
  71. //# sourceMappingURL=skipUntil.js.map