@@ -11,6 +11,8 @@ import {ConnectableObservable} from './observable/ConnectableObservable';
11
11
import { Subject } from './Subject' ;
12
12
import { Notification } from './Notification' ;
13
13
import { toSubscriber } from './util/toSubscriber' ;
14
+ import { tryCatch } from './util/tryCatch' ;
15
+ import { errorObject } from './util/errorObject' ;
14
16
15
17
import { combineLatest as combineLatestStatic } from './operator/combineLatest-static' ;
16
18
import { concat as concatStatic } from './operator/concat-static' ;
@@ -136,27 +138,16 @@ export class Observable<T> implements CoreOperators<T> {
136
138
throw new Error ( 'no Promise impl found' ) ;
137
139
}
138
140
139
- let nextHandler : any ;
141
+ const source = this ;
140
142
141
- if ( thisArg ) {
142
- nextHandler = function nextHandlerFn ( value : any ) : void {
143
- const { thisArg, next } = < any > nextHandlerFn ;
144
- return next . call ( thisArg , value ) ;
145
- } ;
146
- nextHandler . thisArg = thisArg ;
147
- nextHandler . next = next ;
148
- } else {
149
- nextHandler = next ;
150
- }
151
-
152
- const promiseCallback = function promiseCallbackFn ( resolve : Function , reject : Function ) {
153
- const { source, nextHandler } = < any > promiseCallbackFn ;
154
- source . subscribe ( nextHandler , reject , resolve ) ;
155
- } ;
156
- ( < any > promiseCallback ) . source = this ;
157
- ( < any > promiseCallback ) . nextHandler = nextHandler ;
158
-
159
- return new PromiseCtor < void > ( promiseCallback ) ;
143
+ return new PromiseCtor < void > ( ( resolve , reject ) => {
144
+ source . subscribe ( ( value : T ) => {
145
+ const result : any = tryCatch ( next ) . call ( thisArg , value ) ;
146
+ if ( result === errorObject ) {
147
+ reject ( errorObject . e ) ;
148
+ }
149
+ } , reject , resolve ) ;
150
+ } ) ;
160
151
}
161
152
162
153
_subscribe ( subscriber : Subscriber < any > ) : Subscription | Function | void {
0 commit comments