Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
723 bytes
|
Line | |
---|
1 | import { Subscriber } from '../Subscriber';
|
---|
2 | export function pairwise() {
|
---|
3 | return (source) => source.lift(new PairwiseOperator());
|
---|
4 | }
|
---|
5 | class PairwiseOperator {
|
---|
6 | call(subscriber, source) {
|
---|
7 | return source.subscribe(new PairwiseSubscriber(subscriber));
|
---|
8 | }
|
---|
9 | }
|
---|
10 | class PairwiseSubscriber extends Subscriber {
|
---|
11 | constructor(destination) {
|
---|
12 | super(destination);
|
---|
13 | this.hasPrev = false;
|
---|
14 | }
|
---|
15 | _next(value) {
|
---|
16 | let pair;
|
---|
17 | if (this.hasPrev) {
|
---|
18 | pair = [this.prev, value];
|
---|
19 | }
|
---|
20 | else {
|
---|
21 | this.hasPrev = true;
|
---|
22 | }
|
---|
23 | this.prev = value;
|
---|
24 | if (pair) {
|
---|
25 | this.destination.next(pair);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 | //# sourceMappingURL=pairwise.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.