From edb69a8470090d39ac30945b7ef42417764e4ca0 Mon Sep 17 00:00:00 2001 From: Simon DUAN Date: Mon, 18 Mar 2019 14:49:59 +0800 Subject: [PATCH] docs(operators): Add a simple example in doc string (#4636) * 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 --- src/internal/operators/switchMap.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/internal/operators/switchMap.ts b/src/internal/operators/switchMap.ts index 227a76b75f..a71f71d8a6 100644 --- a/src/internal/operators/switchMap.ts +++ b/src/internal/operators/switchMap.ts @@ -36,6 +36,22 @@ export function switchMap>(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';