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.

audit.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { OuterSubscriber } from '../OuterSubscriber';
  2. import { subscribeToResult } from '../util/subscribeToResult';
  3. export function audit(durationSelector) {
  4. return function auditOperatorFunction(source) {
  5. return source.lift(new AuditOperator(durationSelector));
  6. };
  7. }
  8. class AuditOperator {
  9. constructor(durationSelector) {
  10. this.durationSelector = durationSelector;
  11. }
  12. call(subscriber, source) {
  13. return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
  14. }
  15. }
  16. class AuditSubscriber extends OuterSubscriber {
  17. constructor(destination, durationSelector) {
  18. super(destination);
  19. this.durationSelector = durationSelector;
  20. this.hasValue = false;
  21. }
  22. _next(value) {
  23. this.value = value;
  24. this.hasValue = true;
  25. if (!this.throttled) {
  26. let duration;
  27. try {
  28. const { durationSelector } = this;
  29. duration = durationSelector(value);
  30. }
  31. catch (err) {
  32. return this.destination.error(err);
  33. }
  34. const innerSubscription = subscribeToResult(this, duration);
  35. if (!innerSubscription || innerSubscription.closed) {
  36. this.clearThrottle();
  37. }
  38. else {
  39. this.add(this.throttled = innerSubscription);
  40. }
  41. }
  42. }
  43. clearThrottle() {
  44. const { value, hasValue, throttled } = this;
  45. if (throttled) {
  46. this.remove(throttled);
  47. this.throttled = null;
  48. throttled.unsubscribe();
  49. }
  50. if (hasValue) {
  51. this.value = null;
  52. this.hasValue = false;
  53. this.destination.next(value);
  54. }
  55. }
  56. notifyNext(outerValue, innerValue, outerIndex, innerIndex) {
  57. this.clearThrottle();
  58. }
  59. notifyComplete() {
  60. this.clearThrottle();
  61. }
  62. }
  63. //# sourceMappingURL=audit.js.map