pairwise.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. var pair;
  24. if (this.hasPrev) {
  25. pair = [this.prev, value];
  26. }
  27. else {
  28. this.hasPrev = true;
  29. }
  30. this.prev = value;
  31. if (pair) {
  32. this.destination.next(pair);
  33. }
  34. };
  35. return PairwiseSubscriber;
  36. }(Subscriber));
  37. //# sourceMappingURL=pairwise.js.map