distinct.js 1000 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.distinct = void 0;
  4. var lift_1 = require("../util/lift");
  5. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  6. var noop_1 = require("../util/noop");
  7. var innerFrom_1 = require("../observable/innerFrom");
  8. function distinct(keySelector, flushes) {
  9. return lift_1.operate(function (source, subscriber) {
  10. var distinctKeys = new Set();
  11. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  12. var key = keySelector ? keySelector(value) : value;
  13. if (!distinctKeys.has(key)) {
  14. distinctKeys.add(key);
  15. subscriber.next(value);
  16. }
  17. }));
  18. flushes && innerFrom_1.innerFrom(flushes).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function () { return distinctKeys.clear(); }, noop_1.noop));
  19. });
  20. }
  21. exports.distinct = distinct;
  22. //# sourceMappingURL=distinct.js.map