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 innerSubscribe_1 = require("../innerSubscribe");
|
---|
17 | function distinct(keySelector, flushes) {
|
---|
18 | return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
|
---|
19 | }
|
---|
20 | exports.distinct = distinct;
|
---|
21 | var DistinctOperator = (function () {
|
---|
22 | function DistinctOperator(keySelector, flushes) {
|
---|
23 | this.keySelector = keySelector;
|
---|
24 | this.flushes = flushes;
|
---|
25 | }
|
---|
26 | DistinctOperator.prototype.call = function (subscriber, source) {
|
---|
27 | return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
|
---|
28 | };
|
---|
29 | return DistinctOperator;
|
---|
30 | }());
|
---|
31 | var DistinctSubscriber = (function (_super) {
|
---|
32 | __extends(DistinctSubscriber, _super);
|
---|
33 | function DistinctSubscriber(destination, keySelector, flushes) {
|
---|
34 | var _this = _super.call(this, destination) || this;
|
---|
35 | _this.keySelector = keySelector;
|
---|
36 | _this.values = new Set();
|
---|
37 | if (flushes) {
|
---|
38 | _this.add(innerSubscribe_1.innerSubscribe(flushes, new innerSubscribe_1.SimpleInnerSubscriber(_this)));
|
---|
39 | }
|
---|
40 | return _this;
|
---|
41 | }
|
---|
42 | DistinctSubscriber.prototype.notifyNext = function () {
|
---|
43 | this.values.clear();
|
---|
44 | };
|
---|
45 | DistinctSubscriber.prototype.notifyError = function (error) {
|
---|
46 | this._error(error);
|
---|
47 | };
|
---|
48 | DistinctSubscriber.prototype._next = function (value) {
|
---|
49 | if (this.keySelector) {
|
---|
50 | this._useKeySelector(value);
|
---|
51 | }
|
---|
52 | else {
|
---|
53 | this._finalizeNext(value, value);
|
---|
54 | }
|
---|
55 | };
|
---|
56 | DistinctSubscriber.prototype._useKeySelector = function (value) {
|
---|
57 | var key;
|
---|
58 | var destination = this.destination;
|
---|
59 | try {
|
---|
60 | key = this.keySelector(value);
|
---|
61 | }
|
---|
62 | catch (err) {
|
---|
63 | destination.error(err);
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | this._finalizeNext(key, value);
|
---|
67 | };
|
---|
68 | DistinctSubscriber.prototype._finalizeNext = function (key, value) {
|
---|
69 | var values = this.values;
|
---|
70 | if (!values.has(key)) {
|
---|
71 | values.add(key);
|
---|
72 | this.destination.next(value);
|
---|
73 | }
|
---|
74 | };
|
---|
75 | return DistinctSubscriber;
|
---|
76 | }(innerSubscribe_1.SimpleOuterSubscriber));
|
---|
77 | exports.DistinctSubscriber = DistinctSubscriber;
|
---|
78 | //# sourceMappingURL=distinct.js.map |
---|