Skip to content

Commit 4202ad4

Browse files
committed
6b progress
1 parent 4c8759a commit 4202ad4

File tree

3 files changed

+60
-84
lines changed

3 files changed

+60
-84
lines changed

src/content/6/en/part6b.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ We decide to implement the filter functionality by storing <i>the value of the f
8787
}
8888
```
8989

90-
Only the array of notes is stored in the state of the current implementation of our application. In the new implementation, the state object has two properties, <i>notes</i> that contains the array of notes and <i>filter</i> that contains a string indicating which notes should be displayed to the user.
90+
Only the array of notes was stored in the state of the previous implementation of our application. In the new implementation, the state object has two properties, <i>notes</i> that contains the array of notes and <i>filter</i> that contains a string indicating which notes should be displayed to the user.
9191

9292
### Combined reducers
9393

@@ -113,7 +113,7 @@ The actions for changing the state of the filter look like this:
113113
}
114114
```
115115

116-
Let's also create a new _action creator_ function. We will write the code for the action creator in a new <i>src/reducers/filterReducer.js</i> module:
116+
Let's also create a new _action creator_ function. We will write its code in a new <i>src/reducers/filterReducer.js</i> module:
117117

118118
```js
119119
const filterReducer = (state = 'ALL', action) => {
@@ -135,7 +135,6 @@ We can create the actual reducer for our application by combining the two existi
135135
Let's define the combined reducer in the <i>main.jsx</i> file:
136136

137137
```js
138-
import React from 'react'
139138
import ReactDOM from 'react-dom/client'
140139
import { createStore, combineReducers } from 'redux' // highlight-line
141140
import { Provider } from 'react-redux'
@@ -214,9 +213,9 @@ const filterReducer = (state = 'ALL', action) => {
214213

215214
Based on the console output one might get the impression that every action gets duplicated:
216215

217-
![devtools console output showing dupblicated actions in note and filter reducers](../../images/6/6.png)
216+
![devtools console output showing duplicated actions in note and filter reducers](../../images/6/6.png)
218217

219-
Is there a bug in our code? No. The combined reducer works in such a way that every <i>action</i> gets handled in <i>every</i> part of the combined reducer. Typically only one reducer is interested in any given action, but there are situations where multiple reducers change their respective parts of the state based on the same action.
218+
Is there a bug in our code? No. The combined reducer works in such a way that every <i>action</i> gets handled in <i>every</i> part of the combined reducer, or in other words, every reducer "listens" to all of the dispatched actions and does something with them if it has been instructed to do so. Typically only one reducer is interested in any given action, but there are situations where multiple reducers change their respective parts of the state based on the same action.
220219

221220
### Finishing the filters
222221

@@ -305,7 +304,7 @@ const VisibilityFilter = (props) => {
305304
export default VisibilityFilter
306305
```
307306

308-
With the new component <i>App</i> can be simplified as follows:
307+
With the new component, <i>App</i> can be simplified as follows:
309308

310309
```js
311310
import Notes from './components/Notes'
@@ -387,7 +386,7 @@ The current version of the application can be found on [GitHub](https://github.c
387386
388387
### Exercise 6.9
389388
390-
#### 6.9 Better anecdotes, step7
389+
#### 6.9 Better Anecdotes, step 7
391390
392391
Implement filtering for the anecdotes that are displayed to the user.
393392
@@ -433,7 +432,6 @@ npm install @reduxjs/toolkit
433432
Next, open the <i>main.jsx</i> file which currently creates the Redux store. Instead of Redux's <em>createStore</em> function, let's create the store using Redux Toolkit's [configureStore](https://redux-toolkit.js.org/api/configureStore) function:
434433
435434
```js
436-
import React from 'react'
437435
import ReactDOM from 'react-dom/client'
438436
import { Provider } from 'react-redux'
439437
import { configureStore } from '@reduxjs/toolkit' // highlight-line
@@ -460,7 +458,7 @@ ReactDOM.createRoot(document.getElementById('root')).render(
460458
)
461459
```
462460
463-
We already got rid of a few lines of code now that we don't need the <em>combineReducers</em> function to create the reducer for the store. We will soon see that the <em>configureStore</em> function has many additional benefits such as the effortless integration of development tools and many commonly used libraries without the need for additional configuration.
461+
We already got rid of a few lines of code, now we don't need the <em>combineReducers</em> function to create the store's reducer. We will soon see that the <em>configureStore</em> function has many additional benefits such as the effortless integration of development tools and many commonly used libraries without the need for additional configuration.
464462
465463
Let's move on to refactoring the reducers, which brings forth the benefits of the Redux Toolkit. With Redux Toolkit, we can easily create reducer and related action creators using the [createSlice](https://redux-toolkit.js.org/api/createSlice) function. We can use the <em>createSlice</em> function to refactor the reducer and action creators in the <i>reducers/noteReducer.js</i> file in the following manner:
466464

src/content/6/es/part6a.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ El primer parámetro es el <i>estado</i> en el store. El reducer devuelve un <i>
7676

7777
Cambiemos un poco el código. Hemos utilizado declaraciones if-else para responder a una acción y cambiar el estado. Sin embargo, la declaración [switch](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Statements/switch) es el enfoque más común para escribir un reducer.
7878

79-
También definamos un [valor predeterminado](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Functions/Default_parameters) de 0 para el parámetro <i>state</i>. Ahora, el reducer funciona incluso si el estado del almacenamiento aún no se ha inicializado.
79+
También definamos un [valor predeterminado](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Functions/Default_parameters) de 0 para el parámetro <i>state</i>. Ahora, el reducer funciona incluso si el estado del store aún no se ha inicializado.
8080

8181
```js
8282
// highlight-start
@@ -935,7 +935,7 @@ ReactDOM.createRoot(document.getElementById('root')).render(
935935
Ten en cuenta que la aplicación ahora se define como un elemento secundario de un componente [Provider](https://react-redux.js.org/api/provider) (proveedor) proporcionado por la librería react-redux.
936936
El store de la aplicación se entrega al Provider como su atributo store.
937937

938-
La definición de los creadores de acciones se ha movido al archivo <i>reducers/noteReducer.js</i> donde se define el reducer. El archivo se ve así:
938+
La definición de los action creators se ha movido al archivo <i>reducers/noteReducer.js</i> donde se define el reducer. El archivo se ve así:
939939

940940
```js
941941
const noteReducer = (state = [], action) => {

0 commit comments

Comments
 (0)