@@ -3,9 +3,6 @@ import {Observable} from '../Observable';
3
3
import { Subscriber } from '../Subscriber' ;
4
4
import { Subscription } from '../Subscription' ;
5
5
6
- import { tryCatch } from '../util/tryCatch' ;
7
- import { errorObject } from '../util/errorObject' ;
8
-
9
6
import { OuterSubscriber } from '../OuterSubscriber' ;
10
7
import { InnerSubscriber } from '../InnerSubscriber' ;
11
8
import { subscribeToResult } from '../util/subscribeToResult' ;
@@ -34,7 +31,6 @@ class DebounceOperator<T> implements Operator<T, T> {
34
31
}
35
32
36
33
class DebounceSubscriber < T , R > extends OuterSubscriber < T , R > {
37
-
38
34
private value : T ;
39
35
private hasValue : boolean = false ;
40
36
private durationSubscription : Subscription = null ;
@@ -44,31 +40,38 @@ class DebounceSubscriber<T, R> extends OuterSubscriber<T, R> {
44
40
super ( destination ) ;
45
41
}
46
42
47
- protected _next ( value : T ) {
48
- let subscription = this . durationSubscription ;
49
- const duration = tryCatch ( this . durationSelector ) ( value ) ;
43
+ protected _next ( value : T ) : void {
44
+ try {
45
+ const result = this . durationSelector . call ( this , value ) ;
50
46
51
- if ( duration === errorObject ) {
52
- this . destination . error ( errorObject . e ) ;
53
- } else {
54
- this . value = value ;
55
- this . hasValue = true ;
56
- if ( subscription ) {
57
- subscription . unsubscribe ( ) ;
58
- this . remove ( subscription ) ;
59
- }
60
- subscription = subscribeToResult ( this , duration ) ;
61
- if ( ! subscription . isUnsubscribed ) {
62
- this . add ( this . durationSubscription = subscription ) ;
47
+ if ( result ) {
48
+ this . _tryNext ( value , result ) ;
63
49
}
50
+ } catch ( err ) {
51
+ this . destination . error ( err ) ;
64
52
}
65
53
}
66
54
67
- protected _complete ( ) {
55
+ protected _complete ( ) : void {
68
56
this . emitValue ( ) ;
69
57
this . destination . complete ( ) ;
70
58
}
71
59
60
+ private _tryNext ( value : T , duration : Observable < number > | Promise < number > ) : void {
61
+ let subscription = this . durationSubscription ;
62
+ this . value = value ;
63
+ this . hasValue = true ;
64
+ if ( subscription ) {
65
+ subscription . unsubscribe ( ) ;
66
+ this . remove ( subscription ) ;
67
+ }
68
+
69
+ subscription = subscribeToResult ( this , duration ) ;
70
+ if ( ! subscription . isUnsubscribed ) {
71
+ this . add ( this . durationSubscription = subscription ) ;
72
+ }
73
+ }
74
+
72
75
notifyNext ( outerValue : T , innerValue : R ,
73
76
outerIndex : number , innerIndex : number ,
74
77
innerSub : InnerSubscriber < T , R > ) : void {
@@ -79,7 +82,7 @@ class DebounceSubscriber<T, R> extends OuterSubscriber<T, R> {
79
82
this . emitValue ( ) ;
80
83
}
81
84
82
- emitValue ( ) {
85
+ emitValue ( ) : void {
83
86
if ( this . hasValue ) {
84
87
const value = this . value ;
85
88
const subscription = this . durationSubscription ;
0 commit comments