|
1 | 1 | import { OperatorDoc } from '../operator.model';
|
2 | 2 |
|
3 | 3 | export const concat: OperatorDoc = {
|
4 |
| - 'name': 'concat', |
5 |
| - 'operatorType': 'combination' |
| 4 | + name: 'concat', |
| 5 | + operatorType: 'combination', |
| 6 | + signature: |
| 7 | + 'public static concat(input1: ObservableInput, input2: ObservableInput, scheduler: Scheduler): Observable', |
| 8 | + parameters: [ |
| 9 | + { |
| 10 | + name: 'input1', |
| 11 | + type: 'ObservableInput', |
| 12 | + attribute: '', |
| 13 | + description: 'An input Observable to concatenate with others.' |
| 14 | + }, |
| 15 | + { |
| 16 | + name: 'input2', |
| 17 | + type: 'ObservableInput', |
| 18 | + attribute: '', |
| 19 | + description: |
| 20 | + 'An input Observable to concatenate with others. More than one input Observables may be given as argument.' |
| 21 | + }, |
| 22 | + { |
| 23 | + name: 'scheduler', |
| 24 | + type: 'Scheduler', |
| 25 | + attribute: 'optional default: null', |
| 26 | + description: |
| 27 | + 'An optional IScheduler to schedule each Observable subscription on.' |
| 28 | + } |
| 29 | + ], |
| 30 | + marbleUrl: 'http://reactivex.io/rxjs/img/concat.png', |
| 31 | + shortDescription: { |
| 32 | + description: |
| 33 | + 'Creates an output Observable which sequentially emits all values from given Observable and then moves on to the next.', |
| 34 | + extras: [ |
| 35 | + { |
| 36 | + type: 'Tip', |
| 37 | + text: |
| 38 | + 'Concatenates multiple Observables together by sequentially emitting their values, one Observable after the other.' |
| 39 | + } |
| 40 | + ] |
| 41 | + }, |
| 42 | + walkthrough: { |
| 43 | + description: ` |
| 44 | + <p><span class='markdown-code'>concat</span> joins multiple Observables together, by subscribing to them one at a time and |
| 45 | + merging their results into the output Observable. You can pass either an array of |
| 46 | + Observables, or put them directly as arguments. Passing an empty array will result |
| 47 | + in Observable that completes immediately.</p> |
| 48 | +
|
| 49 | + <p><span class='markdown-code'>concat</span> will subscribe to first input Observable and emit all its values, without |
| 50 | + changing or affecting them in any way. When that Observable completes, it will |
| 51 | + subscribe to then next Observable passed and, again, emit its values. This will be |
| 52 | + repeated, until the operator runs out of Observables. When last input Observable completes, |
| 53 | + <span class='markdown-code'>concat</span> will complete as well. At any given moment only one Observable passed to operator |
| 54 | + emits values. If you would like to emit values from passed Observables concurrently, check out |
| 55 | + <a href='/#/operators/merge' class='markdown-code'>merge</a> instead, especially with optional |
| 56 | + <span class='markdown-code'>concurrent</span> parameter. |
| 57 | + As a matter of fact, <span class='markdown-code'>concat</span> is an equivalent of |
| 58 | + <a href='/#/operators/merge' class='markdown-code'>merge</a> operator with |
| 59 | + <span class='markdown-code'>concurrent</span> parameter set to <span class='markdown-code'>1</span>.</p> |
| 60 | +
|
| 61 | + <p>Note that if some input Observable never completes, <span class='markdown-code'>concat</span> will also never complete |
| 62 | + and Observables following the one that did not complete will never be subscribed. On the other |
| 63 | + hand, if some Observable simply completes immediately after it is subscribed, it will be |
| 64 | + invisible for <span class='markdown-code'>concat</span>, which will just move on to the next Observable.</p> |
| 65 | +
|
| 66 | + <p>If any Observable in chain errors, instead of passing control to the next Observable, |
| 67 | + <span class='markdown-code'>concat</span> will error immediately as well. Observables that would be subscribed after |
| 68 | + the one that emitted error, never will.</p> |
| 69 | +
|
| 70 | + <p>If you pass to <span class='markdown-code'>concat</span> the same Observable many times, its stream of values |
| 71 | + will be 'replayed' on every subscription, which means you can repeat given Observable |
| 72 | + as many times as you like. If passing the same Observable to <span class='markdown-code'>concat</span> 1000 times becomes tedious, |
| 73 | + you can always use <span class='markdown-code'>repeat</span>.</p> |
| 74 | + ` |
| 75 | + }, |
| 76 | + examples: [ |
| 77 | + { |
| 78 | + name: |
| 79 | + 'Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10', |
| 80 | + code: ` |
| 81 | + const timer = Rx.Observable.interval(1000).take(4); |
| 82 | + const sequence = Rx.Observable.range(1, 10); |
| 83 | + const result = Rx.Observable.concat(timer, sequence); |
| 84 | + result.subscribe(x => console.log(x)); |
| 85 | +
|
| 86 | + // results in: |
| 87 | + // 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10 |
| 88 | + `, |
| 89 | + externalLink: { |
| 90 | + platform: 'JSBin', |
| 91 | + url: 'http://jsbin.com/doqoyimaxu/embed?js,console' |
| 92 | + } |
| 93 | + }, |
| 94 | + { |
| 95 | + name: 'Concatenate an array of 3 Observables', |
| 96 | + code: ` |
| 97 | + const timer1 = Rx.Observable.interval(1000).take(10); |
| 98 | + const timer2 = Rx.Observable.interval(2000).take(6); |
| 99 | + const timer3 = Rx.Observable.interval(500).take(10); |
| 100 | + const result = timer1.concat(timer2, timer3); |
| 101 | + result.subscribe(x => console.log(x)); |
| 102 | +
|
| 103 | + // results in the following: |
| 104 | + // (Prints to console sequentially) |
| 105 | + // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9 |
| 106 | + // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5 |
| 107 | + // -500ms-> 0 -500ms-> 1 -500ms-> ... 9 |
| 108 | + `, |
| 109 | + externalLink: { |
| 110 | + platform: 'JSBin', |
| 111 | + url: 'http://jsbin.com/decaromone/1/embed?js,console' |
| 112 | + } |
| 113 | + } |
| 114 | + ], |
| 115 | + relatedOperators: ['concatAll', 'concatMap', 'concatMapTo'] |
6 | 116 | };
|
0 commit comments