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 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var tryCatch_1 = require("../util/tryCatch");
  17. var errorObject_1 = require("../util/errorObject");
  18. var OuterSubscriber_1 = require("../OuterSubscriber");
  19. var subscribeToResult_1 = require("../util/subscribeToResult");
  20. function audit(durationSelector) {
  21. return function auditOperatorFunction(source) {
  22. return source.lift(new AuditOperator(durationSelector));
  23. };
  24. }
  25. exports.audit = audit;
  26. var AuditOperator = (function () {
  27. function AuditOperator(durationSelector) {
  28. this.durationSelector = durationSelector;
  29. }
  30. AuditOperator.prototype.call = function (subscriber, source) {
  31. return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
  32. };
  33. return AuditOperator;
  34. }());
  35. var AuditSubscriber = (function (_super) {
  36. __extends(AuditSubscriber, _super);
  37. function AuditSubscriber(destination, durationSelector) {
  38. var _this = _super.call(this, destination) || this;
  39. _this.durationSelector = durationSelector;
  40. _this.hasValue = false;
  41. return _this;
  42. }
  43. AuditSubscriber.prototype._next = function (value) {
  44. this.value = value;
  45. this.hasValue = true;
  46. if (!this.throttled) {
  47. var duration = tryCatch_1.tryCatch(this.durationSelector)(value);
  48. if (duration === errorObject_1.errorObject) {
  49. this.destination.error(errorObject_1.errorObject.e);
  50. }
  51. else {
  52. var innerSubscription = subscribeToResult_1.subscribeToResult(this, duration);
  53. if (!innerSubscription || innerSubscription.closed) {
  54. this.clearThrottle();
  55. }
  56. else {
  57. this.add(this.throttled = innerSubscription);
  58. }
  59. }
  60. }
  61. };
  62. AuditSubscriber.prototype.clearThrottle = function () {
  63. var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled;
  64. if (throttled) {
  65. this.remove(throttled);
  66. this.throttled = null;
  67. throttled.unsubscribe();
  68. }
  69. if (hasValue) {
  70. this.value = null;
  71. this.hasValue = false;
  72. this.destination.next(value);
  73. }
  74. };
  75. AuditSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
  76. this.clearThrottle();
  77. };
  78. AuditSubscriber.prototype.notifyComplete = function () {
  79. this.clearThrottle();
  80. };
  81. return AuditSubscriber;
  82. }(OuterSubscriber_1.OuterSubscriber));
  83. //# sourceMappingURL=audit.js.map