takeWhile.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Emits values emitted by the source Observable so long as each value satisfies
  6. * the given `predicate`, and then completes as soon as this `predicate` is not
  7. * satisfied.
  8. *
  9. * <span class="informal">Takes values from the source only while they pass the
  10. * condition given. When the first value does not satisfy, it completes.</span>
  11. *
  12. * <img src="./img/takeWhile.png" width="100%">
  13. *
  14. * `takeWhile` subscribes and begins mirroring the source Observable. Each value
  15. * emitted on the source is given to the `predicate` function which returns a
  16. * boolean, representing a condition to be satisfied by the source values. The
  17. * output Observable emits the source values until such time as the `predicate`
  18. * returns false, at which point `takeWhile` stops mirroring the source
  19. * Observable and completes the output Observable.
  20. *
  21. * @example <caption>Emit click events only while the clientX property is greater than 200</caption>
  22. * var clicks = Rx.Observable.fromEvent(document, 'click');
  23. * var result = clicks.takeWhile(ev => ev.clientX > 200);
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link take}
  27. * @see {@link takeLast}
  28. * @see {@link takeUntil}
  29. * @see {@link skip}
  30. *
  31. * @param {function(value: T, index: number): boolean} predicate A function that
  32. * evaluates a value emitted by the source Observable and returns a boolean.
  33. * Also takes the (zero-based) index as the second argument.
  34. * @return {Observable<T>} An Observable that emits the values from the source
  35. * Observable so long as each value satisfies the condition defined by the
  36. * `predicate`, then completes.
  37. * @method takeWhile
  38. * @owner Observable
  39. */
  40. function takeWhile(predicate) {
  41. return operators_1.takeWhile(predicate)(this);
  42. }
  43. exports.takeWhile = takeWhile;
  44. //# sourceMappingURL=takeWhile.js.map