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.

distinct.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 OuterSubscriber_1 = require("../OuterSubscriber");
  17. var subscribeToResult_1 = require("../util/subscribeToResult");
  18. function distinct(keySelector, flushes) {
  19. return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
  20. }
  21. exports.distinct = distinct;
  22. var DistinctOperator = (function () {
  23. function DistinctOperator(keySelector, flushes) {
  24. this.keySelector = keySelector;
  25. this.flushes = flushes;
  26. }
  27. DistinctOperator.prototype.call = function (subscriber, source) {
  28. return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
  29. };
  30. return DistinctOperator;
  31. }());
  32. var DistinctSubscriber = (function (_super) {
  33. __extends(DistinctSubscriber, _super);
  34. function DistinctSubscriber(destination, keySelector, flushes) {
  35. var _this = _super.call(this, destination) || this;
  36. _this.keySelector = keySelector;
  37. _this.values = new Set();
  38. if (flushes) {
  39. _this.add(subscribeToResult_1.subscribeToResult(_this, flushes));
  40. }
  41. return _this;
  42. }
  43. DistinctSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  44. this.values.clear();
  45. };
  46. DistinctSubscriber.prototype.notifyError = function (error, innerSub) {
  47. this._error(error);
  48. };
  49. DistinctSubscriber.prototype._next = function (value) {
  50. if (this.keySelector) {
  51. this._useKeySelector(value);
  52. }
  53. else {
  54. this._finalizeNext(value, value);
  55. }
  56. };
  57. DistinctSubscriber.prototype._useKeySelector = function (value) {
  58. var key;
  59. var destination = this.destination;
  60. try {
  61. key = this.keySelector(value);
  62. }
  63. catch (err) {
  64. destination.error(err);
  65. return;
  66. }
  67. this._finalizeNext(key, value);
  68. };
  69. DistinctSubscriber.prototype._finalizeNext = function (key, value) {
  70. var values = this.values;
  71. if (!values.has(key)) {
  72. values.add(key);
  73. this.destination.next(value);
  74. }
  75. };
  76. return DistinctSubscriber;
  77. }(OuterSubscriber_1.OuterSubscriber));
  78. exports.DistinctSubscriber = DistinctSubscriber;
  79. //# sourceMappingURL=distinct.js.map