74 lines
No EOL
2.7 KiB
JavaScript
74 lines
No EOL
2.7 KiB
JavaScript
"use strict";
|
|
var __extends = (this && this.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
}
|
|
return function (d, b) {
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var Subscriber_1 = require("../Subscriber");
|
|
function distinctUntilChanged(compare, keySelector) {
|
|
return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
|
|
}
|
|
exports.distinctUntilChanged = distinctUntilChanged;
|
|
var DistinctUntilChangedOperator = (function () {
|
|
function DistinctUntilChangedOperator(compare, keySelector) {
|
|
this.compare = compare;
|
|
this.keySelector = keySelector;
|
|
}
|
|
DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
|
|
return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
|
|
};
|
|
return DistinctUntilChangedOperator;
|
|
}());
|
|
var DistinctUntilChangedSubscriber = (function (_super) {
|
|
__extends(DistinctUntilChangedSubscriber, _super);
|
|
function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
|
|
var _this = _super.call(this, destination) || this;
|
|
_this.keySelector = keySelector;
|
|
_this.hasKey = false;
|
|
if (typeof compare === 'function') {
|
|
_this.compare = compare;
|
|
}
|
|
return _this;
|
|
}
|
|
DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
|
|
return x === y;
|
|
};
|
|
DistinctUntilChangedSubscriber.prototype._next = function (value) {
|
|
var key;
|
|
try {
|
|
var keySelector = this.keySelector;
|
|
key = keySelector ? keySelector(value) : value;
|
|
}
|
|
catch (err) {
|
|
return this.destination.error(err);
|
|
}
|
|
var result = false;
|
|
if (this.hasKey) {
|
|
try {
|
|
var compare = this.compare;
|
|
result = compare(this.key, key);
|
|
}
|
|
catch (err) {
|
|
return this.destination.error(err);
|
|
}
|
|
}
|
|
else {
|
|
this.hasKey = true;
|
|
}
|
|
if (!result) {
|
|
this.key = key;
|
|
this.destination.next(value);
|
|
}
|
|
};
|
|
return DistinctUntilChangedSubscriber;
|
|
}(Subscriber_1.Subscriber));
|
|
//# sourceMappingURL=distinctUntilChanged.js.map
|