Skip to content

Commit 42e6a9d

Browse files
authored
Merge pull request #2567 from Juanescacha/part7
[es] Part7 Update
2 parents bd3ee0d + a7eaa14 commit 42e6a9d

File tree

5 files changed

+168
-161
lines changed

5 files changed

+168
-161
lines changed

src/content/7/en/part7e.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ However, MVC architecture is not usually mentioned when talking about React appl
254254

255255
Because both React and [Flux](https://facebook.github.io/flux/docs/in-depth-overview) were created at Facebook, one could say that using React only as a UI library is the intended use case. Following the Flux architecture adds some overhead to the application, and if we're talking about a small application or prototype, it might be a good idea to use React "wrong", since [over-engineering](https://en.wikipedia.org/wiki/Overengineering) rarely yields an optimal result.
256256

257-
Part 6 [last chapter](/part6/react_query_use_reducer_ja_contex) covers the newer trends of state management in React. React's hook functions <i>useReducer</i> and <i>useContext</i> provide a kind of lightweight version of Redux. <i>React Query</i>, on the other hand, is a library that solves many of the problems associated with handling state on the server, eliminating the need for a React application to store data retrieved from the server directly in frontend state.
257+
Part 6 [last chapter](/en/part6/react_query_use_reducer_and_the_context) covers the newer trends of state management in React. React's hook functions <i>useReducer</i> and <i>useContext</i> provide a kind of lightweight version of Redux. <i>React Query</i>, on the other hand, is a library that solves many of the problems associated with handling state on the server, eliminating the need for a React application to store data retrieved from the server directly in frontend state.
258258

259259
### React/node-application security
260260

src/content/7/en/part7f.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ Take Prettier to use in your app and configure it to work with your editor.
3535

3636
#### 7.10: Redux, step1
3737

38-
Refactor the application from using the internal React component state to using Redux for the application's state management.
39-
40-
Change the application's notifications to use Redux at this point of the exercise set.
38+
Refactor the application to use Redux to manage the notification data.
4139

4240
#### 7.11: Redux, step2
4341

src/content/7/es/part7d.md

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -738,20 +738,17 @@ Guardemos el siguiente contenido en el archivo <i>db.json</i>:
738738
}
739739
```
740740
741-
742741
Nuestro objetivo es configurar la aplicación con webpack de tal manera que, cuando se use localmente, la aplicación use el servidor json disponible en el puerto 3001 como su backend.
743742
743+
El archivo empaquetado se configurará para usar el backend disponible en la URL <https://notes2023.fly.dev/api/notes>.
744744
745-
El archivo empaquetado se configurará para usar el backend disponible en la URL <https://blooming-atoll-75500.herokuapp.com/api/notes>.
746-
747-
748-
Instalaremos <i>axios</i>, iniciaremos el json-server y luego realizaremos los cambios necesarios en la aplicación. Con el fin de cambiar las cosas, obtendremos las notas del backend con nuestro [hook personalizado](/en/part7/custom_hooks) llamado _useNotes_:
745+
Instalaremos <i>axios</i>, iniciaremos el json-server y luego realizaremos los cambios necesarios en la aplicación. Con el fin de cambiar las cosas, obtendremos las notas del backend con nuestro [hook personalizado](/es/part7/hooks_personalizados) llamado _useNotes_:
749746
750747
```js
748+
// highlight-start
751749
import React, { useState, useEffect } from 'react'
752750
import axios from 'axios'
753751

754-
// highlight-start
755752
const useNotes = (url) => {
756753
const [notes, setNotes] = useState([])
757754

@@ -768,7 +765,7 @@ const useNotes = (url) => {
768765
const App = () => {
769766
const [counter, setCounter] = useState(0)
770767
const [values, setValues] = useState([])
771-
const url = 'https://blooming-atoll-75500.herokuapp.com/api/notes'
768+
const url = 'https://notes2023.fly.dev/api/notes' // highlight-line
772769
const notes = useNotes(url) // highlight-line
773770

774771
const handleClick = () => {
@@ -779,7 +776,7 @@ const App = () => {
779776
return (
780777
<div className="container">
781778
hello webpack {counter} clicks
782-
<button onClick={handleClick} >press</button>
779+
<button onClick={handleClick}>press</button>
783780
<div>{notes.length} notes on server {url}</div> // highlight-line
784781
</div>
785782
)
@@ -788,39 +785,24 @@ const App = () => {
788785
export default App
789786
```
790787
791-
792788
La dirección del servidor backend está actualmente hardcodeada en el código de la aplicación. ¿Cómo podemos cambiar la dirección de forma controlada para que apunte al servidor de backend de producción cuando el código está empaquetado para producción?
793789
794-
795-
Cambiemos el objeto de configuración en el archivo <i>webpack.config.js</i> para que sea una función en lugar de un objeto:
790+
La función de configuración de webpack tiene dos parámetros, <i>env</i> y <i>argv</i>. Podemos usar el segundo para averiguar el <i>modo</i> definido en el script npm:
796791
797792
```js
798-
const path = require('path');
793+
const path = require('path')
799794

800-
const config = (env, argv) => {
795+
const config = (env, argv) => { // highlight-line
796+
console.log('argv.mode:', argv.mode)
801797
return {
802-
entry: './src/index.js',
803-
output: {
804-
// ...
805-
},
806-
devServer: {
807-
// ...
808-
},
809-
devtool: 'source-map',
810-
module: {
811-
// ...
812-
},
813-
plugins: [
814-
// ...
815-
],
798+
// ...
816799
}
817800
}
818801

819802
module.exports = config
820803
```
821804
822-
La definición sigue siendo casi exactamente la misma, excepto por el hecho de que la función ahora devuelve el objeto de configuración. La función recibe los dos parámetros, <i>env</i> y <i>argv</i>, el segundo de los cuales se puede utilizar para acceder al <i>modo</i> definido en el script npm.
823-
805+
Ahora bien, si queremos, podemos configurar webpack para que funcione de manera diferente dependiendo de si el entorno de operación de la aplicación, o <i>mode</i>, está configurado para producción o desarrollo.
824806
825807
También podemos usar [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) de webpack para definir <i>constantes predeterminadas globales</i> que se pueden usar en el código incluido. Definamos una nueva constante global <i>BACKEND\_URL</i>, que obtiene un valor diferente según el entorno para el que se empaqueta el código:
826808
@@ -833,8 +815,8 @@ const config = (env, argv) => {
833815

834816
// highlight-start
835817
const backend_url = argv.mode === 'production'
836-
? 'https://blooming-atoll-75500.herokuapp.com/api/notes'
837-
: 'http://localhost:3001/api/notes'
818+
? 'https://notes2023.fly.dev/api/notes'
819+
: 'http://localhost:3001/notes'
838820
// highlight-end
839821

840822
return {
@@ -844,7 +826,7 @@ const config = (env, argv) => {
844826
filename: 'main.js'
845827
},
846828
devServer: {
847-
contentBase: path.resolve(__dirname, 'build'),
829+
static: path.resolve(__dirname, 'build'),
848830
compress: true,
849831
port: 3000,
850832
},
@@ -865,7 +847,6 @@ const config = (env, argv) => {
865847
module.exports = config
866848
```
867849
868-
869850
La constante global se usa de la siguiente manera en el código:
870851
871852
```js
@@ -885,23 +866,20 @@ const App = () => {
885866
}
886867
```
887868
888-
889869
Si la configuración para el desarrollo y la producción difiere mucho, puede ser una buena idea [separar la configuración](https://webpack.js.org/guides/production/) de los dos en sus propios archivos.
890870
871+
Ahora, si la aplicación se inicia con el comando _npm start_ en modo de desarrollo, obtiene las notas de la dirección http://localhost:3001/notes. La versión empaquetada con el comando _npm run build_ usa la dirección https://notes2023.fly.dev/api/notes para obtener la lista de notas.
891872
892-
Podemos inspeccionar la versión de producción empaquetada de la aplicación localmente ejecutando el siguiente comando en el directorio de <i>compilación</i>:
873+
Podemos inspeccionar la versión de producción empaquetada de la aplicación localmente ejecutando el siguiente comando en el directorio de <i>compilación/build</i>:
893874
894875
```js
895876
npx static-server
896877
```
897878
898-
899879
De forma predeterminada, la aplicación incluida estará disponible en <http://localhost:9080>.
900880
901-
902881
### Polyfill
903882
904-
905883
Nuestra aplicación está terminada y funciona con todas las versiones relativamente recientes de los navegadores modernos, con la excepción de Internet Explorer. La razón de esto es que debido a _axios_, nuestro código usa [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), y ninguna versión existente de IE las admite:
906884
907885
![](../../images/7/29.png)

0 commit comments

Comments
 (0)