Skip to content

Commit 032d936

Browse files
committed
Fix example bugs with random seeds and sorted notifications
1 parent 41042ad commit 032d936

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

docs/tutorials/essentials/part-5-async-logic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The project also includes a small HTTP API client object that exposes `client.ge
4040

4141
We'll use the `client` object to make HTTP calls to our in-memory fake REST API for this section.
4242

43-
Also, the mock server has been set up to reuse the same random seed each time the page is loaded, so that it will generate the same list of fake users and fake posts. If you want to reset that, delete the `'randomTimestampSeed'` value in your browser's Local Storage and reload the page, or you can turn that off by editing `src/api/server.js` and commenting out the `setRandom(rng)` call.
43+
Also, the mock server has been set up to reuse the same random seed each time the page is loaded, so that it will generate the same list of fake users and fake posts. If you want to reset that, delete the `'randomTimestampSeed'` value in your browser's Local Storage and reload the page, or you can turn that off by editing `src/api/server.js` and setting `useSeededRNG` to `false`.
4444

4545
:::info
4646

docs/tutorials/essentials/part-6-performance-normalization.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const fetchNotifications = createAsyncThunk(
147147
'notifications/fetchNotifications',
148148
async (_, { getState }) => {
149149
const allNotifications = selectAllNotifications(getState())
150-
const [latestNotification] = allNotifications.slice(-1)
150+
const [latestNotification] = allNotifications
151151
const latestTimestamp = latestNotification ? latestNotification.date : ''
152152
const response = await client.get(
153153
`/fakeApi/notifications?since=${latestTimestamp}`
@@ -163,7 +163,7 @@ const notificationsSlice = createSlice({
163163
extraReducers: {
164164
[fetchNotifications.fulfilled]: (state, action) => {
165165
state.push(...action.payload)
166-
// Sort with newest last
166+
// Sort with newest first
167167
state.sort((a, b) => b.date.localeCompare(a.date))
168168
}
169169
}
@@ -202,7 +202,7 @@ For more details on these arguments and how to handle canceling thunks and reque
202202

203203
:::
204204

205-
In this case, we know that the list of notifications is in our Redux store state, and that the latest notification should be last in the array. We can destructure the `getState` function out of the `thunkAPI` object, call it to read the state value, and use the `selectAllNotifications` selector to give us just the array of notifications. Then, to get the last item in the array, we can use `allNotifications.slice(-1)` to create a new array with just the last item, and destructure that. (It's a bit tricky, but also nicer to read than doing `allNotifications[allNotifications.length - 1]`.)
205+
In this case, we know that the list of notifications is in our Redux store state, and that the latest notification should be first in the array. We can destructure the `getState` function out of the `thunkAPI` object, call it to read the state value, and use the `selectAllNotifications` selector to give us just the array of notifications. Since the array of notifications is sorted newest first, we can grab the latest one using array destructuring.
206206

207207
### Adding the Notifications List
208208

@@ -329,7 +329,7 @@ const notificationsSlice = createSlice({
329329
})
330330
// highlight-end
331331
state.push(...action.payload)
332-
// Sort with newest last
332+
// Sort with newest first
333333
state.sort((a, b) => b.date.localeCompare(a.date))
334334
}
335335
}
Loading
Loading
Loading

0 commit comments

Comments
 (0)