UNPKG

@reactivex/rxjs

Version:

Reactive Extensions for modern JavaScript

54 lines 1.94 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; define(["require", "exports", '../Subscriber'], function (require, exports, Subscriber_1) { "use strict"; /** * Returns a new observable that triggers on the second and following inputs. * An input that triggers an event will return an pair of [(N - 1)th, Nth]. * The (N-1)th is stored in the internal state until Nth input occurs. * * <img src="./img/pairwise.png" width="100%"> * * @return {Observable<R>} an observable of pairs of values. * @method pairwise * @owner Observable */ function pairwise() { return this.lift(new PairwiseOperator()); } exports.pairwise = pairwise; var PairwiseOperator = (function () { function PairwiseOperator() { } PairwiseOperator.prototype.call = function (subscriber, source) { return source._subscribe(new PairwiseSubscriber(subscriber)); }; return PairwiseOperator; }()); /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var PairwiseSubscriber = (function (_super) { __extends(PairwiseSubscriber, _super); function PairwiseSubscriber(destination) { _super.call(this, destination); this.hasPrev = false; } PairwiseSubscriber.prototype._next = function (value) { if (this.hasPrev) { this.destination.next([this.prev, value]); } else { this.hasPrev = true; } this.prev = value; }; return PairwiseSubscriber; }(Subscriber_1.Subscriber)); }); //# sourceMappingURL=pairwise.js.map