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.1 KB
|
Line | |
---|
1 | import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
|
---|
2 | export function sample(notifier) {
|
---|
3 | return (source) => source.lift(new SampleOperator(notifier));
|
---|
4 | }
|
---|
5 | class SampleOperator {
|
---|
6 | constructor(notifier) {
|
---|
7 | this.notifier = notifier;
|
---|
8 | }
|
---|
9 | call(subscriber, source) {
|
---|
10 | const sampleSubscriber = new SampleSubscriber(subscriber);
|
---|
11 | const subscription = source.subscribe(sampleSubscriber);
|
---|
12 | subscription.add(innerSubscribe(this.notifier, new SimpleInnerSubscriber(sampleSubscriber)));
|
---|
13 | return subscription;
|
---|
14 | }
|
---|
15 | }
|
---|
16 | class SampleSubscriber extends SimpleOuterSubscriber {
|
---|
17 | constructor() {
|
---|
18 | super(...arguments);
|
---|
19 | this.hasValue = false;
|
---|
20 | }
|
---|
21 | _next(value) {
|
---|
22 | this.value = value;
|
---|
23 | this.hasValue = true;
|
---|
24 | }
|
---|
25 | notifyNext() {
|
---|
26 | this.emitValue();
|
---|
27 | }
|
---|
28 | notifyComplete() {
|
---|
29 | this.emitValue();
|
---|
30 | }
|
---|
31 | emitValue() {
|
---|
32 | if (this.hasValue) {
|
---|
33 | this.hasValue = false;
|
---|
34 | this.destination.next(this.value);
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
38 | //# sourceMappingURL=sample.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.