Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion 01-fundamentos-desarrollo/00-inmutabilidad.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pnpm create vite pruebas --template vanilla-ts
Podemos arrancarlo

```bash
npm run dev
pnpm run dev
```

Y lo vemos funcionando en http://localhost:5173/
Expand Down Expand Up @@ -117,6 +117,8 @@ const creaClienteVIP = (nombre: string, apellidos: string): Cliente => {
- };
+ const nuevoCliente: Cliente = {
+ ...clientePlantilla,
+ nombre: nombre,
+ apellidos: apellidos,
+ descuento: clientePlantilla.descuento * 2,
+ };
return nuevoCliente;
Expand All @@ -134,6 +136,8 @@ De hecho podríamos haber escrito esto de forma aún más corta:
```ts
const creaClienteVIP = (nombre: string, apellidos: string): Cliente => ({
...clientePlantilla,
nombre,
apellidos,
descuento: clientePlantilla.descuento * 2,
});
```
6 changes: 5 additions & 1 deletion 01-fundamentos-desarrollo/01-spread-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ console.log("Cliente plantilla:", clientePlantilla);
const creaClienteVIP = (nombre: string, apellidos: string): Cliente => {
const nuevoCliente: Cliente = {
...clientePlantilla,
nombre,
apellidos,
+ descuento: {
+ ...clientePlantilla.descuento,
+ },
Expand All @@ -116,6 +118,8 @@ Y si queremos ser más elegantes:
const creaClienteVIP = (nombre: string, apellidos: string): Cliente => {
const nuevoCliente: Cliente = {
...clientePlantilla,
nombre,
apellidos,
descuento: {
...clientePlantilla.descuento,
+ valor: clientePlantilla.descuento.valor * 2,
Expand All @@ -133,7 +137,7 @@ Pero si tenemos objetos con varios niveles de anidación, esto se puede volver u
Vamos a instalarla:

```bash
npm install immer
pnpm install immer
```

Y ahora podemos hacer esto:
Expand Down