pairwise.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { Subscriber } from '../Subscriber';
  4. export function pairwise() {
  5. return function (source) { return source.lift(new PairwiseOperator()); };
  6. }
  7. var PairwiseOperator = /*@__PURE__*/ (function () {
  8. function PairwiseOperator() {
  9. }
  10. PairwiseOperator.prototype.call = function (subscriber, source) {
  11. return source.subscribe(new PairwiseSubscriber(subscriber));
  12. };
  13. return PairwiseOperator;
  14. }());
  15. var PairwiseSubscriber = /*@__PURE__*/ (function (_super) {
  16. tslib_1.__extends(PairwiseSubscriber, _super);
  17. function PairwiseSubscriber(destination) {
  18. var _this = _super.call(this, destination) || this;
  19. _this.hasPrev = false;
  20. return _this;
  21. }
  22. PairwiseSubscriber.prototype._next = function (value) {
  23. if (this.hasPrev) {
  24. this.destination.next([this.prev, value]);
  25. }
  26. else {
  27. this.hasPrev = true;
  28. }
  29. this.prev = value;
  30. };
  31. return PairwiseSubscriber;
  32. }(Subscriber));
  33. //# sourceMappingURL=pairwise.js.map