audit.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.audit = void 0;
  4. var lift_1 = require("../util/lift");
  5. var innerFrom_1 = require("../observable/innerFrom");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. function audit(durationSelector) {
  8. return lift_1.operate(function (source, subscriber) {
  9. var hasValue = false;
  10. var lastValue = null;
  11. var durationSubscriber = null;
  12. var isComplete = false;
  13. var endDuration = function () {
  14. durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
  15. durationSubscriber = null;
  16. if (hasValue) {
  17. hasValue = false;
  18. var value = lastValue;
  19. lastValue = null;
  20. subscriber.next(value);
  21. }
  22. isComplete && subscriber.complete();
  23. };
  24. var cleanupDuration = function () {
  25. durationSubscriber = null;
  26. isComplete && subscriber.complete();
  27. };
  28. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  29. hasValue = true;
  30. lastValue = value;
  31. if (!durationSubscriber) {
  32. innerFrom_1.innerFrom(durationSelector(value)).subscribe((durationSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, endDuration, cleanupDuration)));
  33. }
  34. }, function () {
  35. isComplete = true;
  36. (!hasValue || !durationSubscriber || durationSubscriber.closed) && subscriber.complete();
  37. }));
  38. });
  39. }
  40. exports.audit = audit;
  41. //# sourceMappingURL=audit.js.map