-
Notifications
You must be signed in to change notification settings - Fork 62
docs(operators): add documentation for concatMap #272
base: master
Are you sure you want to change the base?
Changes from 4 commits
93d729d
73e5d94
8915406
d5f0191
0598275
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,78 @@ | ||
import { OperatorDoc } from '../operator.model'; | ||
|
||
export const concatMap: OperatorDoc = { | ||
'name': 'concatMap', | ||
'operatorType': 'transformation' | ||
name: 'concatMap', | ||
operatorType: 'transformation', | ||
signature: `concatMap(project: (value: T, index: number) => ObservableInput<I>, | ||
?resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): Observable`, | ||
parameters: [ | ||
{ | ||
name: 'project', | ||
type: 'function(value: T, index: number): ObservableInput', | ||
attribute: '', | ||
description: `A function that, when applied to an item emitted by the source | ||
Observable, returns an Observable.` | ||
}, | ||
{ | ||
name: 'resultSelector', | ||
type: | ||
'function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any', | ||
attribute: 'optional', | ||
description: `A function to produce the value on the output Observable based on the values | ||
and the indices of the source (outer) emission and the inner Observable | ||
emission. The arguments passed to this function are: | ||
- 'outerValue': the value that came from the source. | ||
- 'innerValue': the value that came from the projected Observable. | ||
- 'outerIndex': the "index" of the value that came from the source. | ||
- 'innerIndex': the "index" of the value from the projected Observable.` | ||
} | ||
], | ||
marbleUrl: 'http://reactivex.io/rxjs/img/concatMap.png', | ||
shortDescription: { | ||
description: `Project each source value to an Observable which is merge in the output observable, | ||
in a serialized fashion waiting for each one to complete before merging the next one | ||
<span class="informal">Maps each value to an Observable, then flattens all of | ||
these inner Observables using <a href="#/operators/concatAll">concatAll</a>.</span>` | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a few updates:
|
||
walkthrough: { | ||
description: `the source observable maps values to inner observable, subscribe and emit in order. | ||
After subscribing the source observable is ended therefore the concatMap's project function | ||
is only executed once. the second parameter 'resultFunction', allows you to access to the index of | ||
source observable and inner observable (besides the items)` | ||
}, | ||
examples: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if a better starting example for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I think this example could works to prove the singularity of concatMap: with mergeMap the project Function is executed every time I make a click (it could produce memory leaks): with switchMap the project Function is executed every time I make a click but it ends the active subscription until switch to another observable: Please check the live example, https://stackblitz.com/edit/concatmap?file=index.ts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm 🤔 about this one. I think this example shows how The first time The example also uses a resultSelector function, and it looks like those are probably going to get the axe: ReactiveX/rxjs#3304 It might be best to omit them from examples on the docs here. |
||
{ | ||
name: | ||
'Map the first click to inner observable (it ended the Observable of clicks)', | ||
code: ` | ||
import { Observable } from 'rxjs/Observable'; | ||
import { interval } from 'rxjs/observable/interval'; | ||
import { fromEvent } from 'rxjs/observable/fromEvent'; | ||
|
||
import { mapTo, concatMap } from 'rxjs/operators'; | ||
|
||
const $click = fromEvent(document, 'click'); | ||
const $interval = interval(3000) | ||
.pipe(mapTo((iClick, iInterval) => 'Click('+iClick+')'+', '+'Interval('+iInterval+')')); | ||
// the ConcatMap's project function is executed just one time! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would update to: |
||
// Even if you make aditional cliks the ConcatMap's project function is not longer executed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small typo, |
||
// output; Click(0), Interval(0) -> Click(0), Interval(1) -> Click(0), Interval(2) -> etc | ||
$click.pipe(concatMap(() => $interval, | ||
(fromSource, fromInterval, indexSource, indexInterval) => fromInterval(indexSource, indexInterval))) | ||
.subscribe(console.log); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, could you add the expected output. Maybe take a look at the documentation guidelines. There are some tipps and tricks for documenting operators. Thanks for PR!!! |
||
`, | ||
externalLink: { | ||
platform: 'JSBin', | ||
url: 'https://stackblitz.com/edit/concatmap?file=index.ts' | ||
} | ||
} | ||
], | ||
relatedOperators: [ | ||
'concat', | ||
'concatAll', | ||
'concatMapTo', | ||
'exhaustMap', | ||
'mergeMap', | ||
'switchMap' | ||
] | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are going without generic signature, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about it, It was based on the switchMap docs, https://github.com/ReactiveX/rxjs-docs/blob/master/src/operator-docs/transformation/switchMap.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am changing to the not generic version. 👍