File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 1
1
import { Observable } from '../Observable' ;
2
2
import { Operator } from '../Operator' ;
3
3
import { Subscriber } from '../Subscriber' ;
4
- import { tryCatch } from '../util/tryCatch' ;
5
- import { errorObject } from '../util/errorObject' ;
6
4
7
5
/**
8
6
* Returns an Observable that applies a specified accumulator function to the first item emitted by a source Observable,
@@ -48,21 +46,27 @@ export class ReduceSubscriber<T, R> extends Subscriber<T> {
48
46
this . hasSeed = typeof seed !== 'undefined' ;
49
47
}
50
48
51
- protected _next ( x : T ) {
49
+ next ( value : T ) {
52
50
if ( this . hasValue || ( this . hasValue = this . hasSeed ) ) {
53
- const result = tryCatch ( this . project ) . call ( this , this . acc , x ) ;
54
- if ( result === errorObject ) {
55
- this . destination . error ( errorObject . e ) ;
56
- } else {
57
- this . acc = result ;
58
- }
51
+ this . _tryReduce ( value ) ;
59
52
} else {
60
- this . acc = x ;
53
+ this . acc = value ;
61
54
this . hasValue = true ;
62
55
}
63
56
}
64
57
65
- protected _complete ( ) {
58
+ private _tryReduce ( value : T ) {
59
+ let result : any ;
60
+ try {
61
+ result = this . project ( < R > this . acc , value ) ;
62
+ } catch ( err ) {
63
+ this . destination . error ( err ) ;
64
+ return ;
65
+ }
66
+ this . acc = result ;
67
+ }
68
+
69
+ complete ( ) {
66
70
if ( this . hasValue || this . hasSeed ) {
67
71
this . destination . next ( this . acc ) ;
68
72
}
You can’t perform that action at this time.
0 commit comments