File tree Expand file tree Collapse file tree 3 files changed +16
-33
lines changed Expand file tree Collapse file tree 3 files changed +16
-33
lines changed Original file line number Diff line number Diff line change 1
- import { Operator } from '../Operator' ;
2
- import { Subscriber } from '../Subscriber' ;
1
+
3
2
import { Observable } from '../Observable' ;
3
+ import { toArray as higherOrder } from '../operators' ;
4
4
5
5
/**
6
6
* @return {Observable<any[]>|WebSocketSubject<T>|Observable<T> }
7
7
* @method toArray
8
8
* @owner Observable
9
9
*/
10
10
export function toArray < T > ( this : Observable < T > ) : Observable < T [ ] > {
11
- return this . lift ( new ToArrayOperator ( ) ) ;
12
- }
13
-
14
- class ToArrayOperator < T > implements Operator < T , T [ ] > {
15
- call ( subscriber : Subscriber < T [ ] > , source : any ) : any {
16
- return source . subscribe ( new ToArraySubscriber ( subscriber ) ) ;
17
- }
18
- }
19
-
20
- /**
21
- * We need this JSDoc comment for affecting ESDoc.
22
- * @ignore
23
- * @extends {Ignored }
24
- */
25
- class ToArraySubscriber < T > extends Subscriber < T > {
26
-
27
- private array : T [ ] = [ ] ;
28
-
29
- constructor ( destination : Subscriber < T [ ] > ) {
30
- super ( destination ) ;
31
- }
32
-
33
- protected _next ( x : T ) {
34
- this . array . push ( x ) ;
35
- }
36
-
37
- protected _complete ( ) {
38
- this . destination . next ( this . array ) ;
39
- this . destination . complete ( ) ;
40
- }
41
- }
11
+ return higherOrder ( ) ( this ) ;
12
+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export { switchAll } from './switchAll';
22
22
export { switchMap } from './switchMap' ;
23
23
export { takeLast } from './takeLast' ;
24
24
export { tap } from './tap' ;
25
+ export { toArray } from './toArray' ;
25
26
export { window } from './window' ;
26
27
export { windowCount } from './windowCount' ;
27
28
export { windowTime } from './windowTime' ;
Original file line number Diff line number Diff line change
1
+ import { reduce } from './reduce' ;
2
+ import { OperatorFunction } from '../interfaces' ;
3
+
4
+ function toArrayReducer < T > ( acc : T [ ] , value : T ) {
5
+ acc . push ( value ) ;
6
+ return acc ;
7
+ }
8
+
9
+ export function toArray < T > ( ) : OperatorFunction < T , T [ ] > {
10
+ return reduce ( toArrayReducer , [ ] ) ;
11
+ }
You can’t perform that action at this time.
0 commit comments