om/node_modules/rxjs/internal/operators/distinctUntilChanged.js

74 lines
2.9 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");
var tryCatch_1 = require("../util/tryCatch");
var errorObject_1 = require("../util/errorObject");
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 keySelector = this.keySelector;
var key = value;
if (keySelector) {
key = tryCatch_1.tryCatch(this.keySelector)(value);
if (key === errorObject_1.errorObject) {
return this.destination.error(errorObject_1.errorObject.e);
}
}
var result = false;
if (this.hasKey) {
result = tryCatch_1.tryCatch(this.compare)(this.key, key);
if (result === errorObject_1.errorObject) {
return this.destination.error(errorObject_1.errorObject.e);
}
}
else {
this.hasKey = true;
}
if (Boolean(result) === false) {
this.key = key;
this.destination.next(value);
}
};
return DistinctUntilChangedSubscriber;
}(Subscriber_1.Subscriber));
//# sourceMappingURL=distinctUntilChanged.js.map