Skip to content

Commit 8dac19e

Browse files
authored
Update part6a.md
Hi, I have added "// highlight-start" and "// highlight-stop" to code sections, to highlight better the code in sections without highlighting... I think is better to follow the logic of any explanation of how was done until here... Thanks, Armando
1 parent 1e7548b commit 8dac19e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/content/6/es/part6a.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ Cambiemos un poco el código. Es habitual usar el comando [switch](https://devel
9090
Definamos también un [valor predeterminado](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) de 0 para el <i>estado</i> del parámetro . Ahora el reducer funciona incluso si el estado del store aún no se ha indicado.
9191

9292
```js
93+
// highlight-start
9394
const counterReducer = (state = 0, action) => {
95+
// highlight-end
9496
switch (action.type) {
9597
case 'INCREMENT':
9698
return state + 1
@@ -108,13 +110,17 @@ const counterReducer = (state = 0, action) => {
108110
No se supone que Reducer se llame directamente desde el código de la aplicación. Reducer solo se proporciona como parámetro a la función _createStore_ que crea el store:
109111

110112
```js
113+
// highlight-start
111114
import { createStore } from 'redux'
115+
// highlight-end
112116

113117
const counterReducer = (state = 0, action) => {
114118
// ...
115119
}
116120

121+
// highlight-start
117122
const store = createStore(counterReducer)
123+
// highlight-end
118124
```
119125

120126

@@ -383,7 +389,9 @@ Agregamos una nueva nota al estado con el método _state.push(action.data)_ que
383389
```js
384390
const noteReducer = (state = [], action) => {
385391
if (action.type === 'NEW_NOTE') {
392+
// highlight-start
386393
return state.concat(action.data)
394+
// highlight-stop
387395
}
388396

389397
return state
@@ -568,7 +576,9 @@ Agregar una nueva nota crea el estado que devuelve con la función de Arrays _co
568576
const noteReducer = (state = [], action) => {
569577
switch(action.type) {
570578
case 'NEW_NOTE':
579+
// highlight-start
571580
return [...state, action.data]
581+
// highlight-stop
572582
case 'TOGGLE_IMPORTANCE':
573583
// ...
574584
default:
@@ -754,42 +764,50 @@ Tu aplicación puede tener una apariencia modesta, nada más se necesitan 3 boto
754764
Agreguemos la funcionalidad para agregar nuevas notas y cambiar su importancia:
755765

756766
```js
767+
// highlight-start
757768
const generateId = () =>
758769
Number((Math.random() * 1000000).toFixed(0))
770+
// highlight-stop
759771

760772
const App = () => {
773+
// highlight-start
761774
const addNote = (event) => {
762775
event.preventDefault()
763776
const content = event.target.note.value
764777
event.target.note.value = ''
765778
store.dispatch({
766779
type: 'NEW_NOTE',
767-
data: {
780+
payload: {
768781
content,
769782
important: false,
770783
id: generateId()
771784
}
772785
})
773786
}
787+
// highlight-end
774788

789+
// highlight-start
775790
const toggleImportance = (id) => {
776791
store.dispatch({
777792
type: 'TOGGLE_IMPORTANCE',
778-
data: { id }
793+
payload: { id }
779794
})
780795
}
796+
// highlight-end
781797

782798
return (
783799
<div>
800+
// highlight-start
784801
<form onSubmit={addNote}>
785802
<input name="note" />
786803
<button type="submit">add</button>
787804
</form>
805+
// highlight-end
788806
<ul>
789807
{store.getState().map(note =>
790808
<li
791809
key={note.id}
792-
onClick={() => toggleImportance(note.id)}
810+
onClick={() => toggleImportance(note.id)} // highlight-line
793811
>
794812
{note.content} <strong>{note.important ? 'important' : ''}</strong>
795813
</li>
@@ -800,7 +818,6 @@ const App = () => {
800818
}
801819
```
802820

803-
804821
La implementación de ambas funcionalidades es sencilla. Cabe señalar que <i>no hemos</i> vinculado el estado de los campos del formulario al estado del componente <i>App</i> como lo hicimos anteriormente. React llama a este tipo de formulario [no controlado](https://reactjs.org/docs/uncontrolled-components.html).
805822

806823

0 commit comments

Comments
 (0)