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.

distinctUntilChanged.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 Subscriber_1 = require("../Subscriber");
  17. var tryCatch_1 = require("../util/tryCatch");
  18. var errorObject_1 = require("../util/errorObject");
  19. function distinctUntilChanged(compare, keySelector) {
  20. return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
  21. }
  22. exports.distinctUntilChanged = distinctUntilChanged;
  23. var DistinctUntilChangedOperator = (function () {
  24. function DistinctUntilChangedOperator(compare, keySelector) {
  25. this.compare = compare;
  26. this.keySelector = keySelector;
  27. }
  28. DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
  29. return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
  30. };
  31. return DistinctUntilChangedOperator;
  32. }());
  33. var DistinctUntilChangedSubscriber = (function (_super) {
  34. __extends(DistinctUntilChangedSubscriber, _super);
  35. function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
  36. var _this = _super.call(this, destination) || this;
  37. _this.keySelector = keySelector;
  38. _this.hasKey = false;
  39. if (typeof compare === 'function') {
  40. _this.compare = compare;
  41. }
  42. return _this;
  43. }
  44. DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
  45. return x === y;
  46. };
  47. DistinctUntilChangedSubscriber.prototype._next = function (value) {
  48. var keySelector = this.keySelector;
  49. var key = value;
  50. if (keySelector) {
  51. key = tryCatch_1.tryCatch(this.keySelector)(value);
  52. if (key === errorObject_1.errorObject) {
  53. return this.destination.error(errorObject_1.errorObject.e);
  54. }
  55. }
  56. var result = false;
  57. if (this.hasKey) {
  58. result = tryCatch_1.tryCatch(this.compare)(this.key, key);
  59. if (result === errorObject_1.errorObject) {
  60. return this.destination.error(errorObject_1.errorObject.e);
  61. }
  62. }
  63. else {
  64. this.hasKey = true;
  65. }
  66. if (Boolean(result) === false) {
  67. this.key = key;
  68. this.destination.next(value);
  69. }
  70. };
  71. return DistinctUntilChangedSubscriber;
  72. }(Subscriber_1.Subscriber));
  73. //# sourceMappingURL=distinctUntilChanged.js.map