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.

debounce.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { OuterSubscriber } from '../OuterSubscriber';
  4. import { subscribeToResult } from '../util/subscribeToResult';
  5. export function debounce(durationSelector) {
  6. return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
  7. }
  8. var DebounceOperator = /*@__PURE__*/ (function () {
  9. function DebounceOperator(durationSelector) {
  10. this.durationSelector = durationSelector;
  11. }
  12. DebounceOperator.prototype.call = function (subscriber, source) {
  13. return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
  14. };
  15. return DebounceOperator;
  16. }());
  17. var DebounceSubscriber = /*@__PURE__*/ (function (_super) {
  18. tslib_1.__extends(DebounceSubscriber, _super);
  19. function DebounceSubscriber(destination, durationSelector) {
  20. var _this = _super.call(this, destination) || this;
  21. _this.durationSelector = durationSelector;
  22. _this.hasValue = false;
  23. _this.durationSubscription = null;
  24. return _this;
  25. }
  26. DebounceSubscriber.prototype._next = function (value) {
  27. try {
  28. var result = this.durationSelector.call(this, value);
  29. if (result) {
  30. this._tryNext(value, result);
  31. }
  32. }
  33. catch (err) {
  34. this.destination.error(err);
  35. }
  36. };
  37. DebounceSubscriber.prototype._complete = function () {
  38. this.emitValue();
  39. this.destination.complete();
  40. };
  41. DebounceSubscriber.prototype._tryNext = function (value, duration) {
  42. var subscription = this.durationSubscription;
  43. this.value = value;
  44. this.hasValue = true;
  45. if (subscription) {
  46. subscription.unsubscribe();
  47. this.remove(subscription);
  48. }
  49. subscription = subscribeToResult(this, duration);
  50. if (subscription && !subscription.closed) {
  51. this.add(this.durationSubscription = subscription);
  52. }
  53. };
  54. DebounceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  55. this.emitValue();
  56. };
  57. DebounceSubscriber.prototype.notifyComplete = function () {
  58. this.emitValue();
  59. };
  60. DebounceSubscriber.prototype.emitValue = function () {
  61. if (this.hasValue) {
  62. var value = this.value;
  63. var subscription = this.durationSubscription;
  64. if (subscription) {
  65. this.durationSubscription = null;
  66. subscription.unsubscribe();
  67. this.remove(subscription);
  68. }
  69. this.value = null;
  70. this.hasValue = false;
  71. _super.prototype._next.call(this, value);
  72. }
  73. };
  74. return DebounceSubscriber;
  75. }(OuterSubscriber));
  76. //# sourceMappingURL=debounce.js.map