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.

filter.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Subscriber } from '../Subscriber';
  2. export function filter(predicate, thisArg) {
  3. return function filterOperatorFunction(source) {
  4. return source.lift(new FilterOperator(predicate, thisArg));
  5. };
  6. }
  7. class FilterOperator {
  8. constructor(predicate, thisArg) {
  9. this.predicate = predicate;
  10. this.thisArg = thisArg;
  11. }
  12. call(subscriber, source) {
  13. return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
  14. }
  15. }
  16. class FilterSubscriber extends Subscriber {
  17. constructor(destination, predicate, thisArg) {
  18. super(destination);
  19. this.predicate = predicate;
  20. this.thisArg = thisArg;
  21. this.count = 0;
  22. }
  23. _next(value) {
  24. let result;
  25. try {
  26. result = this.predicate.call(this.thisArg, value, this.count++);
  27. }
  28. catch (err) {
  29. this.destination.error(err);
  30. return;
  31. }
  32. if (result) {
  33. this.destination.next(value);
  34. }
  35. }
  36. }
  37. //# sourceMappingURL=filter.js.map