|
1 | 1 | import { OperatorDoc } from '../operator.model';
|
2 | 2 |
|
3 | 3 | export const mergeMap: OperatorDoc = {
|
4 |
| - 'name': 'mergeMap', |
5 |
| - 'operatorType': 'transformation' |
| 4 | + name: 'mergeMap', |
| 5 | + operatorType: 'transformation', |
| 6 | + signature: |
| 7 | + 'public mergeMap(project: Function, resultSelector?: Function, concurrent?: number): Observable', |
| 8 | + useInteractiveMarbles: true, |
| 9 | + parameters: [ |
| 10 | + { |
| 11 | + name: 'project', |
| 12 | + type: '(value: T, index: number) => ObservableInput', |
| 13 | + attribute: '', |
| 14 | + description: `A function that, when applied to an item emitted by the source Observable, returns |
| 15 | + an Observable.` |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'resultSelector', |
| 19 | + type: |
| 20 | + '(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => any', |
| 21 | + attribute: 'optional', |
| 22 | + description: `A function to produce the value on the output Observable based on the values and the indices |
| 23 | + of the source (outer) emission and the inner Observable emission. The arguments passed to this function are: |
| 24 | + 'outerValue': the value that came from the source, |
| 25 | + 'innerValue': the value that came from the projected Observable, |
| 26 | + 'outerIndex': the "index" of the value that came from the source, |
| 27 | + 'innerIndex': the "index" of the value from the projected Observable.` |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'concurrent', |
| 31 | + type: 'number', |
| 32 | + attribute: 'optional', |
| 33 | + description: `Maximum number of input Observables being subscribed to concurrently.` |
| 34 | + } |
| 35 | + ], |
| 36 | + marbleUrl: 'http://reactivex.io/rxjs/img/mergeMap.png', |
| 37 | + shortDescription: { |
| 38 | + description: ` |
| 39 | + Projects each source value to an Observable which is merged in the output Observable. |
| 40 | + `, |
| 41 | + extras: [] |
| 42 | + }, |
| 43 | + walkthrough: { |
| 44 | + description: ` |
| 45 | + <p> |
| 46 | + Returns an Observable that emits items based on applying a function that you supply |
| 47 | + to each item emitted by the source Observable, where that function returns an Observable, |
| 48 | + and then merging those resulting Observables and emitting the results of this merger. |
| 49 | + </p> |
| 50 | + ` |
| 51 | + }, |
| 52 | + examples: [ |
| 53 | + { |
| 54 | + name: |
| 55 | + 'Map and flatten each letter to an Observable ticking every 1 second', |
| 56 | + code: ` |
| 57 | + import { of } from 'rxjs/observable/of'; |
| 58 | + import { interval } from 'rxjs/observable/interval'; |
| 59 | + import { mergeMap, map } from 'rxjs/operators'; |
| 60 | +
|
| 61 | + const letters = of('a', 'b', 'c'); |
| 62 | + const result = letters.pipe( |
| 63 | + mergeMap(x => { |
| 64 | + return interval(1000).pipe(map(i => x+i)); |
| 65 | + }) |
| 66 | + ); |
| 67 | + result.subscribe(x => console.log(x)); |
| 68 | +
|
| 69 | + // Output |
| 70 | + "a0" |
| 71 | + "b0" |
| 72 | + "c0" |
| 73 | + "a1" |
| 74 | + "b1" |
| 75 | + "c1" |
| 76 | + "a2" |
| 77 | + "b2" |
| 78 | + "c2" |
| 79 | + `, |
| 80 | + externalLink: { |
| 81 | + platform: 'JSBin', |
| 82 | + url: 'http://jsbin.com/pekelowibe/embed?js,console' |
| 83 | + } |
| 84 | + } |
| 85 | + ], |
| 86 | + relatedOperators: [ |
| 87 | + 'concatMap', |
| 88 | + 'exhaustmap', |
| 89 | + 'merge', |
| 90 | + 'mergeAll', |
| 91 | + 'mergeMapTo', |
| 92 | + 'mergeScan', |
| 93 | + 'switchMap' |
| 94 | + ], |
| 95 | + additionalResources: [] |
6 | 96 | };
|
0 commit comments