Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { Subscriber } from '../Subscriber';
|
---|
2 | export function every(predicate, thisArg) {
|
---|
3 | return (source) => source.lift(new EveryOperator(predicate, thisArg, source));
|
---|
4 | }
|
---|
5 | class EveryOperator {
|
---|
6 | constructor(predicate, thisArg, source) {
|
---|
7 | this.predicate = predicate;
|
---|
8 | this.thisArg = thisArg;
|
---|
9 | this.source = source;
|
---|
10 | }
|
---|
11 | call(observer, source) {
|
---|
12 | return source.subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source));
|
---|
13 | }
|
---|
14 | }
|
---|
15 | class EverySubscriber extends Subscriber {
|
---|
16 | constructor(destination, predicate, thisArg, source) {
|
---|
17 | super(destination);
|
---|
18 | this.predicate = predicate;
|
---|
19 | this.thisArg = thisArg;
|
---|
20 | this.source = source;
|
---|
21 | this.index = 0;
|
---|
22 | this.thisArg = thisArg || this;
|
---|
23 | }
|
---|
24 | notifyComplete(everyValueMatch) {
|
---|
25 | this.destination.next(everyValueMatch);
|
---|
26 | this.destination.complete();
|
---|
27 | }
|
---|
28 | _next(value) {
|
---|
29 | let result = false;
|
---|
30 | try {
|
---|
31 | result = this.predicate.call(this.thisArg, value, this.index++, this.source);
|
---|
32 | }
|
---|
33 | catch (err) {
|
---|
34 | this.destination.error(err);
|
---|
35 | return;
|
---|
36 | }
|
---|
37 | if (!result) {
|
---|
38 | this.notifyComplete(false);
|
---|
39 | }
|
---|
40 | }
|
---|
41 | _complete() {
|
---|
42 | this.notifyComplete(true);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | //# sourceMappingURL=every.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.