Skip to content

Commit

Permalink
docs(operators): Add a simple example in doc string (#4636)
Browse files Browse the repository at this point in the history
* docs(operators): describe your change...

Add much simpler example to help understand what `switchMap` can do. It is easy to understand for document reader.

* update the sample to following TS grammar

* updated according to suggestion

1. mark sample code in typescript
2. space between of(1, 2, 3)
3. outputs

* docs(operators): updated the sample code in docs
  • Loading branch information
xuemind authored and niklas-wortmann committed Mar 18, 2019
1 parent 2b1ebf8 commit edb69a8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/internal/operators/switchMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ export function switchMap<T, R, O extends ObservableInput<any>>(project: (value:
* subsequent inner Observables.
*
* ## Example
* Generate new Observable according to source Observable values
* ```typescript
* import { of } from 'rxjs';
* import { switchMap } from 'rxjs/operators';
*
* const switched = of(1, 2, 3).pipe(switchMap((x: number) => of(x, x ** 2, x ** 3)));
* switched.subscribe(x => console.log(x));
* // outputs
* // 1
* // 1
* // 2
* // 4
* // 8
* // ... and so on
* ```
*
* Rerun an interval Observable on every click event
* ```javascript
* import { fromEvent, interval } from 'rxjs';
Expand Down

0 comments on commit edb69a8

Please sign in to comment.