@@ -5,17 +5,17 @@ title: Github Issues Viewer
55import 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 )
99and [ React] ( https://reactjs.org ) .
1010:::
1111
1212For 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 )
1414of the [ Redux Toolkit] ( https://redux-toolkit.js.org ) .
1515
1616It's a great example because it starts with a plain React application and it then
1717shows 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
1919state 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
250252Now 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,
252254so we can represent this behavior with ` merge ` :
253255
254256``` ts
@@ -282,14 +284,16 @@ const currentRepoAndPage$ = merge(
282284From 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
288292And following our model, the list of issues also depends on this stream, but the
289293list of issues needs to be loaded from the API.
290294
291295In 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.
295299This can be expressed reactively as:
@@ -363,7 +367,7 @@ export const [useIssueComments, issueComments$] = bind(
363367` ` `
364368
365369As 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)
367371in ` @react - rxjs / utils ` that makes it sightly less verbose.
368372
369373Here 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),
550554and we will also take the chance to represent the loading state by
551555using 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
10281032and the one that we have optimised with React-RxJS. Looking at the
10291033Chrome Network tab with 3G for react-state:
10301034
0 commit comments