Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

takeWhile.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Subscriber } from '../Subscriber';
  2. export function takeWhile(predicate, inclusive = false) {
  3. return (source) => source.lift(new TakeWhileOperator(predicate, inclusive));
  4. }
  5. class TakeWhileOperator {
  6. constructor(predicate, inclusive) {
  7. this.predicate = predicate;
  8. this.inclusive = inclusive;
  9. }
  10. call(subscriber, source) {
  11. return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));
  12. }
  13. }
  14. class TakeWhileSubscriber extends Subscriber {
  15. constructor(destination, predicate, inclusive) {
  16. super(destination);
  17. this.predicate = predicate;
  18. this.inclusive = inclusive;
  19. this.index = 0;
  20. }
  21. _next(value) {
  22. const destination = this.destination;
  23. let result;
  24. try {
  25. result = this.predicate(value, this.index++);
  26. }
  27. catch (err) {
  28. destination.error(err);
  29. return;
  30. }
  31. this.nextOrComplete(value, result);
  32. }
  33. nextOrComplete(value, predicateResult) {
  34. const destination = this.destination;
  35. if (Boolean(predicateResult)) {
  36. destination.next(value);
  37. }
  38. else {
  39. if (this.inclusive) {
  40. destination.next(value);
  41. }
  42. destination.complete();
  43. }
  44. }
  45. }
  46. //# sourceMappingURL=takeWhile.js.map