Skip to content

Commit cae5f9b

Browse files
ghetolaybenlesh
authored andcommitted
fix(concatStatic): missing exports for mergeStatic and concatStatic (#2999)
* fix(concatStatic): missing export creating breaking change * refactor(concat/merge): add consistency about definitions and reexport
1 parent 1a9fd42 commit cae5f9b

File tree

5 files changed

+122
-71
lines changed

5 files changed

+122
-71
lines changed

src/observable/merge.ts

+100-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,101 @@
1-
import { mergeStatic } from '../operator/merge';
1+
import { Observable, ObservableInput } from '../Observable';
2+
import { IScheduler } from '../Scheduler';
3+
import { ArrayObservable } from './ArrayObservable';
4+
import { isScheduler } from '../util/isScheduler';
5+
import { mergeAll } from '../operators/mergeAll';
26

3-
export const merge = mergeStatic;
7+
/* tslint:disable:max-line-length */
8+
export function merge<T>(v1: ObservableInput<T>, scheduler?: IScheduler): Observable<T>;
9+
export function merge<T>(v1: ObservableInput<T>, concurrent?: number, scheduler?: IScheduler): Observable<T>;
10+
export function merge<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, scheduler?: IScheduler): Observable<T | T2>;
11+
export function merge<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2>;
12+
export function merge<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, scheduler?: IScheduler): Observable<T | T2 | T3>;
13+
export function merge<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3>;
14+
export function merge<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, scheduler?: IScheduler): Observable<T | T2 | T3 | T4>;
15+
export function merge<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3 | T4>;
16+
export function merge<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5>;
17+
export function merge<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5>;
18+
export function merge<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5 | T6>;
19+
export function merge<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5 | T6>;
20+
export function merge<T>(...observables: (ObservableInput<T> | IScheduler | number)[]): Observable<T>;
21+
export function merge<T, R>(...observables: (ObservableInput<any> | IScheduler | number)[]): Observable<R>;
22+
/* tslint:enable:max-line-length */
23+
/**
24+
* Creates an output Observable which concurrently emits all values from every
25+
* given input Observable.
26+
*
27+
* <span class="informal">Flattens multiple Observables together by blending
28+
* their values into one Observable.</span>
29+
*
30+
* <img src="./img/merge.png" width="100%">
31+
*
32+
* `merge` subscribes to each given input Observable (as arguments), and simply
33+
* forwards (without doing any transformation) all the values from all the input
34+
* Observables to the output Observable. The output Observable only completes
35+
* once all input Observables have completed. Any error delivered by an input
36+
* Observable will be immediately emitted on the output Observable.
37+
*
38+
* @example <caption>Merge together two Observables: 1s interval and clicks</caption>
39+
* var clicks = Rx.Observable.fromEvent(document, 'click');
40+
* var timer = Rx.Observable.interval(1000);
41+
* var clicksOrTimer = Rx.Observable.merge(clicks, timer);
42+
* clicksOrTimer.subscribe(x => console.log(x));
43+
*
44+
* // Results in the following:
45+
* // timer will emit ascending values, one every second(1000ms) to console
46+
* // clicks logs MouseEvents to console everytime the "document" is clicked
47+
* // Since the two streams are merged you see these happening
48+
* // as they occur.
49+
*
50+
* @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
51+
* var timer1 = Rx.Observable.interval(1000).take(10);
52+
* var timer2 = Rx.Observable.interval(2000).take(6);
53+
* var timer3 = Rx.Observable.interval(500).take(10);
54+
* var concurrent = 2; // the argument
55+
* var merged = Rx.Observable.merge(timer1, timer2, timer3, concurrent);
56+
* merged.subscribe(x => console.log(x));
57+
*
58+
* // Results in the following:
59+
* // - First timer1 and timer2 will run concurrently
60+
* // - timer1 will emit a value every 1000ms for 10 iterations
61+
* // - timer2 will emit a value every 2000ms for 6 iterations
62+
* // - after timer1 hits it's max iteration, timer2 will
63+
* // continue, and timer3 will start to run concurrently with timer2
64+
* // - when timer2 hits it's max iteration it terminates, and
65+
* // timer3 will continue to emit a value every 500ms until it is complete
66+
*
67+
* @see {@link mergeAll}
68+
* @see {@link mergeMap}
69+
* @see {@link mergeMapTo}
70+
* @see {@link mergeScan}
71+
*
72+
* @param {...ObservableInput} observables Input Observables to merge together.
73+
* @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
74+
* Observables being subscribed to concurrently.
75+
* @param {Scheduler} [scheduler=null] The IScheduler to use for managing
76+
* concurrency of input Observables.
77+
* @return {Observable} an Observable that emits items that are the result of
78+
* every input Observable.
79+
* @static true
80+
* @name merge
81+
* @owner Observable
82+
*/
83+
export function merge<T, R>(...observables: Array<ObservableInput<any> | IScheduler | number>): Observable<R> {
84+
let concurrent = Number.POSITIVE_INFINITY;
85+
let scheduler: IScheduler = null;
86+
let last: any = observables[observables.length - 1];
87+
if (isScheduler(last)) {
88+
scheduler = <IScheduler>observables.pop();
89+
if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
90+
concurrent = <number>observables.pop();
91+
}
92+
} else if (typeof last === 'number') {
93+
concurrent = <number>observables.pop();
94+
}
95+
96+
if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
97+
return <Observable<R>>observables[0];
98+
}
99+
100+
return mergeAll(concurrent)(new ArrayObservable(<any>observables, scheduler)) as Observable<R>;
101+
}

src/operator/concat.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Observable, ObservableInput } from '../Observable';
22
import { IScheduler } from '../Scheduler';
33
import { concat as higherOrder } from '../operators/concat';
44

5+
export { concat as concatStatic } from '../observable/concat';
6+
57
/* tslint:disable:max-line-length */
68
export function concat<T>(this: Observable<T>, scheduler?: IScheduler): Observable<T>;
79
export function concat<T, T2>(this: Observable<T>, v2: ObservableInput<T2>, scheduler?: IScheduler): Observable<T | T2>;

src/operator/merge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Observable, ObservableInput } from '../Observable';
22
import { IScheduler } from '../Scheduler';
33
import { merge as higherOrder } from '../operators/merge';
44

5-
export { mergeStatic } from '../operators/merge';
5+
export { merge as mergeStatic } from '../observable/merge';
66

77
/* tslint:disable:max-line-length */
88
export function merge<T>(this: Observable<T>, scheduler?: IScheduler): Observable<T>;

src/operators/concat.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { IScheduler } from '../Scheduler';
33
import { OperatorFunction, MonoTypeOperatorFunction } from '../interfaces';
44
import { concat as concatStatic } from '../observable/concat';
55

6+
export { concat as concatStatic } from '../observable/concat';
7+
68
/* tslint:disable:max-line-length */
79
export function concat<T>(scheduler?: IScheduler): MonoTypeOperatorFunction<T>;
810
export function concat<T, T2>(v2: ObservableInput<T2>, scheduler?: IScheduler): OperatorFunction<T, T | T2>;

src/operators/merge.ts

+17-68
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Observable, ObservableInput } from '../Observable';
22
import { IScheduler } from '../Scheduler';
3-
import { ArrayObservable } from '../observable/ArrayObservable';
4-
import { mergeAll } from './mergeAll';
5-
import { isScheduler } from '../util/isScheduler';
63
import { OperatorFunction, MonoTypeOperatorFunction } from '../interfaces';
4+
import { merge as mergeStatic } from '../observable/merge';
5+
6+
export { merge as mergeStatic } from '../observable/merge';
77

88
/* tslint:disable:max-line-length */
99
export function merge<T>(scheduler?: IScheduler): MonoTypeOperatorFunction<T>;
@@ -21,27 +21,6 @@ export function merge<T, T2, T3, T4, T5, T6>(v2: ObservableInput<T2>, v3: Observ
2121
export function merge<T>(...observables: Array<ObservableInput<T> | IScheduler | number>): MonoTypeOperatorFunction<T>;
2222
export function merge<T, R>(...observables: Array<ObservableInput<any> | IScheduler | number>): OperatorFunction<T, R>;
2323
/* tslint:enable:max-line-length */
24-
25-
export function merge<T, R>(...observables: Array<ObservableInput<any> | IScheduler | number>): OperatorFunction<T, R> {
26-
return (source: Observable<T>) => source.lift.call(mergeStatic(source, ...observables));
27-
}
28-
29-
/* tslint:disable:max-line-length */
30-
export function mergeStatic<T>(v1: ObservableInput<T>, scheduler?: IScheduler): Observable<T>;
31-
export function mergeStatic<T>(v1: ObservableInput<T>, concurrent?: number, scheduler?: IScheduler): Observable<T>;
32-
export function mergeStatic<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, scheduler?: IScheduler): Observable<T | T2>;
33-
export function mergeStatic<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2>;
34-
export function mergeStatic<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, scheduler?: IScheduler): Observable<T | T2 | T3>;
35-
export function mergeStatic<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3>;
36-
export function mergeStatic<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, scheduler?: IScheduler): Observable<T | T2 | T3 | T4>;
37-
export function mergeStatic<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3 | T4>;
38-
export function mergeStatic<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5>;
39-
export function mergeStatic<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5>;
40-
export function mergeStatic<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5 | T6>;
41-
export function mergeStatic<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, concurrent?: number, scheduler?: IScheduler): Observable<T | T2 | T3 | T4 | T5 | T6>;
42-
export function mergeStatic<T>(...observables: (ObservableInput<T> | IScheduler | number)[]): Observable<T>;
43-
export function mergeStatic<T, R>(...observables: (ObservableInput<any> | IScheduler | number)[]): Observable<R>;
44-
/* tslint:enable:max-line-length */
4524
/**
4625
* Creates an output Observable which concurrently emits all values from every
4726
* given input Observable.
@@ -51,73 +30,43 @@ export function mergeStatic<T, R>(...observables: (ObservableInput<any> | ISched
5130
*
5231
* <img src="./img/merge.png" width="100%">
5332
*
54-
* `merge` subscribes to each given input Observable (as arguments), and simply
55-
* forwards (without doing any transformation) all the values from all the input
56-
* Observables to the output Observable. The output Observable only completes
57-
* once all input Observables have completed. Any error delivered by an input
58-
* Observable will be immediately emitted on the output Observable.
33+
* `merge` subscribes to each given input Observable (either the source or an
34+
* Observable given as argument), and simply forwards (without doing any
35+
* transformation) all the values from all the input Observables to the output
36+
* Observable. The output Observable only completes once all input Observables
37+
* have completed. Any error delivered by an input Observable will be immediately
38+
* emitted on the output Observable.
5939
*
6040
* @example <caption>Merge together two Observables: 1s interval and clicks</caption>
6141
* var clicks = Rx.Observable.fromEvent(document, 'click');
6242
* var timer = Rx.Observable.interval(1000);
63-
* var clicksOrTimer = Rx.Observable.merge(clicks, timer);
43+
* var clicksOrTimer = clicks.merge(timer);
6444
* clicksOrTimer.subscribe(x => console.log(x));
6545
*
66-
* // Results in the following:
67-
* // timer will emit ascending values, one every second(1000ms) to console
68-
* // clicks logs MouseEvents to console everytime the "document" is clicked
69-
* // Since the two streams are merged you see these happening
70-
* // as they occur.
71-
*
7246
* @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
7347
* var timer1 = Rx.Observable.interval(1000).take(10);
7448
* var timer2 = Rx.Observable.interval(2000).take(6);
7549
* var timer3 = Rx.Observable.interval(500).take(10);
7650
* var concurrent = 2; // the argument
77-
* var merged = Rx.Observable.merge(timer1, timer2, timer3, concurrent);
51+
* var merged = timer1.merge(timer2, timer3, concurrent);
7852
* merged.subscribe(x => console.log(x));
7953
*
80-
* // Results in the following:
81-
* // - First timer1 and timer2 will run concurrently
82-
* // - timer1 will emit a value every 1000ms for 10 iterations
83-
* // - timer2 will emit a value every 2000ms for 6 iterations
84-
* // - after timer1 hits it's max iteration, timer2 will
85-
* // continue, and timer3 will start to run concurrently with timer2
86-
* // - when timer2 hits it's max iteration it terminates, and
87-
* // timer3 will continue to emit a value every 500ms until it is complete
88-
*
8954
* @see {@link mergeAll}
9055
* @see {@link mergeMap}
9156
* @see {@link mergeMapTo}
9257
* @see {@link mergeScan}
9358
*
94-
* @param {...ObservableInput} observables Input Observables to merge together.
59+
* @param {ObservableInput} other An input Observable to merge with the source
60+
* Observable. More than one input Observables may be given as argument.
9561
* @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
9662
* Observables being subscribed to concurrently.
9763
* @param {Scheduler} [scheduler=null] The IScheduler to use for managing
9864
* concurrency of input Observables.
99-
* @return {Observable} an Observable that emits items that are the result of
65+
* @return {Observable} An Observable that emits items that are the result of
10066
* every input Observable.
101-
* @static true
102-
* @name merge
67+
* @method merge
10368
* @owner Observable
10469
*/
105-
export function mergeStatic<T, R>(...observables: Array<ObservableInput<any> | IScheduler | number>): Observable<R> {
106-
let concurrent = Number.POSITIVE_INFINITY;
107-
let scheduler: IScheduler = null;
108-
let last: any = observables[observables.length - 1];
109-
if (isScheduler(last)) {
110-
scheduler = <IScheduler>observables.pop();
111-
if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
112-
concurrent = <number>observables.pop();
113-
}
114-
} else if (typeof last === 'number') {
115-
concurrent = <number>observables.pop();
116-
}
117-
118-
if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
119-
return <Observable<R>>observables[0];
120-
}
121-
122-
return mergeAll(concurrent)(new ArrayObservable(<any>observables, scheduler)) as Observable<R>;
70+
export function merge<T, R>(...observables: Array<ObservableInput<any> | IScheduler | number>): OperatorFunction<T, R> {
71+
return (source: Observable<T>) => source.lift.call(mergeStatic(source, ...observables));
12372
}

0 commit comments

Comments
 (0)