@@ -2,7 +2,7 @@ import { Observable } from '../observable'
22import { Stream } from '../stream'
33import { useUnsubscribeCallback } from '../utils'
44import { StreamTupleValues , PromiseStatus } from '../types'
5- import { getGlobalFluthFactory } from '../utils'
5+ import { getGlobalFluthFactory , checkStreamOrObservableInput } from '../utils'
66
77/**
88 * combine takes multiple streams or Observable, and return a stream that emits values from all the input streams.
@@ -12,23 +12,23 @@ import { getGlobalFluthFactory } from '../utils'
1212 * @returns {Stream }
1313 */
1414export const combine = < T extends ( Stream | Observable ) [ ] > ( ...args$ : T ) => {
15+ // check input type
16+ if ( ! checkStreamOrObservableInput ( args$ , true ) ) {
17+ throw new Error ( 'combine operator only accepts Stream or Observable as input' )
18+ }
19+
1520 const stream$ = ( getGlobalFluthFactory ( ) ?.(
16- args$ . map ( ( arg$ ) => arg$ ? ._getProtectedProperty ?. ( '_v' ) ) as StreamTupleValues < T > ,
21+ args$ . map ( ( arg$ ) => arg$ . _getProtectedProperty ( '_v' ) ) as StreamTupleValues < T > ,
1722 ) ||
1823 new Stream < StreamTupleValues < T > > (
19- args$ . map ( ( arg$ ) => arg$ ? ._getProtectedProperty ?. ( '_v' ) ) as StreamTupleValues < T > ,
24+ args$ . map ( ( arg$ ) => arg$ . _getProtectedProperty ( '_v' ) ) as StreamTupleValues < T > ,
2025 ) ) as Stream < StreamTupleValues < T > >
2126 const payload : StreamTupleValues < T > = [ ] as any
2227 const promiseStatus = [ ...Array ( args$ . length ) ] . map ( ( ) => PromiseStatus . PENDING )
2328 let finishCount = 0
2429 const { unsubscribeCallback } = useUnsubscribeCallback ( stream$ , args$ . length )
2530 const completeCallback = ( ) => ( finishCount += 1 )
2631
27- // check input type
28- if ( args$ . some ( ( arg$ ) => ! ( arg$ instanceof Stream ) && ! ( arg$ instanceof Observable ) ) ) {
29- throw new Error ( 'combine operator only accepts Stream or Observable as input' )
30- }
31-
3232 // if no input, return an empty stream
3333 if ( args$ . length === 0 ) {
3434 return stream$
0 commit comments