Skip to content

Commit 064c8b8

Browse files
volivajosepot
authored andcommitted
remove pluck from examples
1 parent c1a9620 commit 064c8b8

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

docs/examples/CharacterCounter.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React from "react";
2-
import { Subject } from "rxjs";
3-
import { pluck, startWith } from "rxjs/operators";
4-
import { bind } from "@react-rxjs/core";
1+
import React from "react"
2+
import { Subject } from "rxjs"
3+
import { map, startWith } from "rxjs/operators"
4+
import { bind } from "@react-rxjs/core"
55

6-
const textSubject = new Subject();
7-
const setText = (newText) => textSubject.next(newText);
8-
const [useText, text$] = bind(textSubject.pipe(startWith("")));
6+
const textSubject = new Subject()
7+
const setText = (newText) => textSubject.next(newText)
8+
const [useText, text$] = bind(textSubject.pipe(startWith("")))
99

1010
function TextInput() {
11-
const text = useText();
11+
const text = useText()
1212

1313
return (
1414
<div>
@@ -20,15 +20,15 @@ function TextInput() {
2020
<br />
2121
Echo: {text}
2222
</div>
23-
);
23+
)
2424
}
2525

26-
const [useCharCount] = bind(text$.pipe(pluck("length")));
26+
const [useCharCount] = bind(text$.pipe(map((text) => text.length)))
2727

2828
function CharacterCount() {
29-
const count = useCharCount();
29+
const count = useCharCount()
3030

31-
return <>Character Count: {count}</>;
31+
return <>Character Count: {count}</>
3232
}
3333

3434
export default function CharacterCounter() {
@@ -37,5 +37,5 @@ export default function CharacterCounter() {
3737
<TextInput />
3838
<CharacterCount />
3939
</div>
40-
);
40+
)
4141
}

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ function TextInput() {
5151
`bind` returns a tuple that contains the hook, plus the underlying shared observable so it can be used by other streams:
5252

5353
```tsx
54-
import { pluck } from "rxjs/operators"
54+
import { map } from "rxjs/operators"
5555
import { bind } from "@react-rxjs/core"
5656

5757
// Previously...
5858
// const [useText, text$] = bind(...);
5959

60-
const [useCharCount] = bind(text$.pipe(pluck("length")))
60+
const [useCharCount] = bind(text$.pipe(map((text) => text.length)))
6161

6262
function CharacterCount() {
6363
const count = useCharCount()

docs/tutorial/github-issues.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ title: Github Issues Viewer
55
import useBaseUrl from '@docusaurus/useBaseUrl';
66

77
:::info Note
8-
This tutorial assumes you are already familiar with both [RxJS](https://rxjs.dev)
8+
This tutorial assumes you are already familiar with both [RxJS](https://rxjs.dev)
99
and [React](https://reactjs.org).
1010
:::
1111

1212
For this tutorial we will be borrowing the Github issues example that is taught
13-
in the [Advanced Tutorial](https://redux-toolkit.js.org/tutorials/advanced-tutorial)
13+
in the [Advanced Tutorial](https://redux-toolkit.js.org/tutorials/advanced-tutorial)
1414
of the [Redux Toolkit](https://redux-toolkit.js.org).
1515

1616
It's a great example because it starts with a plain React application and it then
1717
shows how to migrate that application to Redux using the Redux Toolkit (RTK). One of the many good
18-
things about the tutorial, is that it illustrates the mental models required to manage
18+
things about the tutorial, is that it illustrates the mental models required to manage
1919
state efficiently with RTK. In this tutorial we will try to follow the same approach.
2020

2121
## Reviewing the Starting Example Application
@@ -90,7 +90,7 @@ of Axios. It's a pretty straightforward change:
9090
-import axios from 'axios'
9191
+import { ajax } from 'rxjs/ajax'
9292
import parseLink, { Links } from 'parse-link-header'
93-
+import { map, pluck } from 'rxjs/operators'
93+
+import { map } from 'rxjs/operators'
9494
+import { Observable } from 'rxjs'
9595

9696
export interface Label {
@@ -149,7 +149,9 @@ of Axios. It's a pretty straightforward change:
149149
-
150150
- const { data } = await axios.get<RepoDetails>(url)
151151
- return data
152-
+ return ajax.getJSON<RepoDetails>(url).pipe(pluck('open_issues_count'))
152+
+ return ajax
153+
+ .getJSON<RepoDetails>(url)
154+
+ .pipe(map((repoDetails) => repoDetails.open_issues_count))
153155
}
154156

155157
-export async function getIssue(org: string, repo: string, number: number) {
@@ -248,7 +250,7 @@ export const onIssueUnselecteed = () => {
248250
```
249251

250252
Now that we already have the top-level streams, let's create a stream that represents
251-
the "current repo and page" entity. We want to reset the page to 1 when the selected repo changes,
253+
the "current repo and page" entity. We want to reset the page to 1 when the selected repo changes,
252254
so we can represent this behavior with `merge`:
253255

254256
```ts
@@ -282,14 +284,16 @@ const currentRepoAndPage$ = merge(
282284
From this stream we can extract the current page:
283285

284286
```ts
285-
export const [useCurrentPage] = bind(currentRepoAndPage$.pipe(pluck("page")))
287+
export const [useCurrentPage] = bind(
288+
currentRepoAndPage$.pipe(map(({ page }) => page)),
289+
)
286290
```
287291

288292
And following our model, the list of issues also depends on this stream, but the
289293
list of issues needs to be loaded from the API.
290294

291295
In this example we also want to use React Suspense: When the user changes the repo
292-
or page, we want to show a suspended state while the new issue list is loading
296+
or page, we want to show a suspended state while the new issue list is loading
293297
(i.e. "Loading issues..."). The way we can do this, is by emitting the
294298
[`SUSPENSE`](../api/core/suspense) symbol, that means that there's data being loaded in this stream.
295299
This can be expressed reactively as:
@@ -363,7 +367,7 @@ export const [useIssueComments, issueComments$] = bind(
363367
```
364368
365369
As this pattern of `switchMap` and `startWith(SUSPENSE)` is something that's
366-
often used, react-rxjs exports [`switchMapSuspended`](../api/utils/switchMapSuspended)
370+
often used, react-rxjs exports [`switchMapSuspended`](../api/utils/switchMapSuspended)
367371
in `@react-rxjs/utils` that makes it sightly less verbose.
368372
369373
Here we also need to create a subscription to `issueComments$` in order to ensure
@@ -546,7 +550,7 @@ export const IssuesListPage = () => {
546550
547551
#### IssuesPageHeader
548552
549-
For the header, we can get rid of its props (as we have already declared its state),
553+
For the header, we can get rid of its props (as we have already declared its state),
550554
and we will also take the chance to represent the loading state by
551555
using React's Suspense:
552556
@@ -1024,7 +1028,7 @@ And use a lazy import with Suspense in App:
10241028
)
10251029
```
10261030
1027-
Now let's compare the speed between the original version without code splitting
1031+
Now let's compare the speed between the original version without code splitting
10281032
and the one that we have optimised with React-RxJS. Looking at the
10291033
Chrome Network tab with 3G for react-state:
10301034

0 commit comments

Comments
 (0)