Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

distinctUntilChanged.js 2.7KB

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