123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Subscriber_1 = require('../Subscriber');
  8. /**
  9. * Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds
  10. * true, but emits all further source items as soon as the condition becomes false.
  11. *
  12. * <img src="./img/skipWhile.png" width="100%">
  13. *
  14. * @param {Function} predicate - A function to test each item emitted from the source Observable.
  15. * @return {Observable<T>} An Observable that begins emitting items emitted by the source Observable when the
  16. * specified predicate becomes false.
  17. * @method skipWhile
  18. * @owner Observable
  19. */
  20. function skipWhile(predicate) {
  21. return function (source) { return source.lift(new SkipWhileOperator(predicate)); };
  22. }
  23. exports.skipWhile = skipWhile;
  24. var SkipWhileOperator = (function () {
  25. function SkipWhileOperator(predicate) {
  26. this.predicate = predicate;
  27. }
  28. SkipWhileOperator.prototype.call = function (subscriber, source) {
  29. return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
  30. };
  31. return SkipWhileOperator;
  32. }());
  33. /**
  34. * We need this JSDoc comment for affecting ESDoc.
  35. * @ignore
  36. * @extends {Ignored}
  37. */
  38. var SkipWhileSubscriber = (function (_super) {
  39. __extends(SkipWhileSubscriber, _super);
  40. function SkipWhileSubscriber(destination, predicate) {
  41. _super.call(this, destination);
  42. this.predicate = predicate;
  43. this.skipping = true;
  44. this.index = 0;
  45. }
  46. SkipWhileSubscriber.prototype._next = function (value) {
  47. var destination = this.destination;
  48. if (this.skipping) {
  49. this.tryCallPredicate(value);
  50. }
  51. if (!this.skipping) {
  52. destination.next(value);
  53. }
  54. };
  55. SkipWhileSubscriber.prototype.tryCallPredicate = function (value) {
  56. try {
  57. var result = this.predicate(value, this.index++);
  58. this.skipping = Boolean(result);
  59. }
  60. catch (err) {
  61. this.destination.error(err);
  62. }
  63. };
  64. return SkipWhileSubscriber;
  65. }(Subscriber_1.Subscriber));
  66. //# sourceMappingURL=skipWhile.js.map