Skip to content

Commit 34ded57

Browse files
authored
Update no-nested-pipe.md
rule usage standalone code for playground
1 parent 5c3db31 commit 34ded57

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

docs/rules/no-nested-pipe.md

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,50 @@ This rule effects failures if `pipe` is called within a `pipe` handler.
77
Examples of **incorrect** code for this rule:
88

99
```ts
10-
import { of, timer } from "rxjs";
11-
12-
of("searchText1", "searchText2").pipe(switchMap((searchText) => {
13-
return this.callSearchAPI(searchText).pipe(map(response => {
14-
......
15-
......
16-
// considering more lines here
17-
})
18-
})
10+
import { switchMap, map, of } from 'rxjs';
11+
12+
of('searchText1', 'searchText2')
13+
.pipe(
14+
switchMap(searchText => {
15+
return callSearchAPI(searchText).pipe(
16+
map(response => {
17+
console.log(response);
18+
return 'final ' + response;
19+
// considering more lines here
20+
})
21+
);
22+
})
23+
)
24+
.subscribe(value => console.log(value));
25+
26+
function callSearchAPI(searchText) {
27+
return of('new' + searchText);
28+
}
29+
30+
1931
```
2032

2133
Examples of **correct** code for this rule:
2234

2335
```ts
24-
import { of, timer } from "rxjs";
25-
import { mapTo, mergeMap } from "rxjs/operators";
26-
27-
of("searchText1", "searchText2").pipe(switchMap((searchText) => this.getDisplayResponse(searchText)))
28-
29-
function getDisplayResponse (){
30-
this.callSearchAPI(searchText).pipe(map(response => {
31-
......
32-
......
33-
// considering more lines here
36+
import { switchMap, map, of } from 'rxjs';
37+
38+
of('searchText1', 'searchText2')
39+
.pipe(
40+
switchMap(searchText => {
41+
return callSearchAPI(searchText);
42+
})
43+
)
44+
.subscribe(value => console.log(value));
45+
46+
function callSearchAPI(searchText) {
47+
return of('new' + searchText).pipe(
48+
map(response => {
49+
console.log(response);
50+
return 'final ' + response;
51+
// considering more lines here
52+
})
53+
);
3454
}
3555

3656
```

0 commit comments

Comments
 (0)