-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs(operators): Spanish translation for map-skip-undefined operator * docs(operators): Spanish translation for reduce-array operator * docs(operators): Spanish translation for rx-effect operator
- Loading branch information
Showing
3 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
docs/src/content/docs/es/utilities/Operators/map-skip-undefined.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: mapSkipUndefined | ||
description: An RxJS operator that allows applying a transform function to each value of the observable in (same as map), but with the ability to skip (filter out) some values if the function explicitly returns undefined or simply doesn't return anything for same code-path (implicit return undefined). | ||
entryPoint: map-skip-undefined | ||
badge: stable | ||
contributors: ['daniele-morosinotto'] | ||
--- | ||
|
||
## Import | ||
|
||
```ts | ||
import { mapSkipUndefined } from 'ngxtension/map-skip-undefined'; | ||
``` | ||
|
||
## Uso | ||
|
||
Se puede usar como un operador normal, pero con la habilidad de saltar ciertos valores: devolviendo undefined (explícito o implçicito). | ||
|
||
```ts | ||
import { from } from 'rxjs'; | ||
import { mapSkipUndefined } from 'ngxtension/map-skip-undefined'; | ||
|
||
const in$ = from([1, 42, 3]); | ||
const out$ = in$.pipe( | ||
mapSkipUndefined((n) => { | ||
if (n % 2) return String(n * 2); | ||
//else revuelve undefined // <-- Es lo mismo que no devolver nada! | ||
//En cualquier caso, el valor par será filtrado | ||
}), | ||
); //infer Observable<string> | ||
|
||
out$.subscribe(console.log); // logs: 2, 6 | ||
``` | ||
|
||
## Bonus: filterUndefined | ||
|
||
Si necesitamos filtrar los valores `undefined` de un stream Observable, podemos usar el operador `filterUndefined`. | ||
|
||
### Ejemplo | ||
|
||
```ts | ||
import { filterUndefined } from 'ngxtension/map-skip-undefined'; | ||
|
||
const source$ = of(null, undefined, 42); | ||
const filtered$ = source$.pipe(filterUndefined()); //solo emite null y 42 | ||
``` |
44 changes: 44 additions & 0 deletions
44
docs/src/content/docs/es/utilities/Operators/reduce-array.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: reduceArray | ||
description: An RxJS operator designed to apply a reduce function to an array within an Observable stream, simplifying array transformations. | ||
entryPoint: reduce-array | ||
badge: stable | ||
contributors: ['tomer'] | ||
--- | ||
|
||
## Import | ||
|
||
```ts | ||
import { reduceArray } from 'ngxtension/reduce-array'; | ||
``` | ||
|
||
## Uso | ||
|
||
### Básico | ||
|
||
Aplica una función de reducción a un array que ha sido emitido por un Observable. | ||
|
||
```ts | ||
import { of } from 'rxjs'; | ||
import { reduceArray } from 'ngxtension/reduce-array'; | ||
|
||
const source$ = of([1, 2, 3]); | ||
const reduced$ = source$.pipe(reduceArray((acc, e) => acc + e, 0)); | ||
``` | ||
|
||
## Ejemplos | ||
|
||
### Ejemplo 1: Suma de los elementos de un Array | ||
|
||
```ts | ||
const source$ = of([1, 2, 3]); | ||
const reduced$ = source$.pipe(reduceArray((acc, e) => acc + e, 0)); | ||
// Output: 6 | ||
``` | ||
|
||
## API | ||
|
||
### Inputs | ||
|
||
- `reduceFn: (accumulator: R, item: T, index: number) => R` - Una función para reducir cada uno de los elementos del array, similar a la función de JavaScript `.reduce()`. | ||
- `initialValue: R` - El valor inicial que se le asigna al acumulador. |
120 changes: 120 additions & 0 deletions
120
docs/src/content/docs/es/utilities/Operators/rx-effect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
--- | ||
title: rxEffect | ||
description: ngxtension/rx-effect | ||
entryPoint: rx-effect | ||
badge: stable | ||
contributors: ['lucas-garcia'] | ||
--- | ||
|
||
`rxEffect` es una utilidad que nos ayuda a crear un side effect con rxjs, devolviendo `Subscription` manejada adecuadamente, con `takeUntilDestroyed` en ella. | ||
|
||
La lógica del effect puede: | ||
|
||
- ser asignada cómo segundo parámetro, cómo si fuera un [`TapObserver`](https://rxjs.dev/api/index/interface/TapObserver) o en la función `next` | ||
- o puede ser directamente manejado en el origen (menos recomendado pero podríamos necesitar hacerlo si nuestro effect necesita estar dentro de un `switchMap` o similar) | ||
|
||
| argumentos | tipo | descripción | | ||
| ----------------- | ---------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | | ||
| `source` | `Observable<T>` | cualquier `Observable` al cual se suscribirá para poder ejecutar el side effect | | ||
| `effectOrOptions` | `TapObserver<T> \| ((value: T) => void) \| { destroyRef: DestroyRef }` | Opcional. El valor por defecto es `undefined`.<br>Un next handler, un observer parcial o un objeto options. | | ||
| `options` | `{ destroyRef: DestroyRef }` | Opcional. El valor por defecto es `undefined`.<br>Un objeto options para proveer `DestroyRef`, si es necesario. | | ||
|
||
```ts | ||
import { rxEffect } from 'ngxtension/rx-effect'; | ||
``` | ||
|
||
## Uso | ||
|
||
Con la función `next` | ||
|
||
```ts | ||
@Component({ | ||
standalone: true, | ||
imports: [ReactiveFormsModule], | ||
selector: 'app-root', | ||
template: ` | ||
<form [formGroup]="user"> | ||
<input type="text" formControlName="firstName" /> | ||
<input type="text" formControlName="lastName" /> | ||
</form> | ||
`, | ||
}) | ||
export class Form { | ||
readonly user = new FormGroup({ | ||
firstName: new FormControl(''), | ||
lastName: new FormControl({ value: '', disabled: true }), | ||
}); | ||
|
||
readonly #toggleLastNameAccess = rxEffect( | ||
this.user.controls.firstName.valueChanges, | ||
(firstName) => { | ||
if (firstName) this.user.controls.lastName.enable(); | ||
else this.user.controls.lastName.disable(); | ||
}, | ||
); | ||
} | ||
``` | ||
|
||
Con `TapObserver` | ||
|
||
```ts | ||
@Component({ | ||
standalone: true, | ||
imports: [ReactiveFormsModule], | ||
selector: 'app-root', | ||
template: ` | ||
<form [formGroup]="user"> | ||
<input type="text" formControlName="firstName" /> | ||
<input type="text" formControlName="lastName" /> | ||
</form> | ||
`, | ||
}) | ||
export class Form { | ||
readonly user = new FormGroup({ | ||
firstName: new FormControl(''), | ||
lastName: new FormControl({ value: '', disabled: true }), | ||
}); | ||
|
||
readonly #toggleLastNameAccess = rxEffect( | ||
this.user.controls.firstName.valueChanges, | ||
{ | ||
next: (firstName) => { | ||
if (firstName) this.user.controls.lastName.enable(); | ||
else this.user.controls.lastName.disable(); | ||
}, | ||
}, | ||
); | ||
} | ||
``` | ||
|
||
Con el effect gestionado directamente en el origen | ||
|
||
```ts | ||
@Component({ | ||
standalone: true, | ||
imports: [ReactiveFormsModule], | ||
selector: 'app-root', | ||
template: ` | ||
<form [formGroup]="user"> | ||
<input type="text" formControlName="firstName" /> | ||
<input type="text" formControlName="lastName" /> | ||
</form> | ||
`, | ||
}) | ||
export class Form { | ||
readonly #userService = injec(UserService); | ||
|
||
readonly user = new FormGroup({ | ||
firstName: new FormControl(''), | ||
lastName: new FormControl(''), | ||
}); | ||
|
||
readonly #saveChangesOnTheFly = rxEffect( | ||
this.user.valueChanges.pipe( | ||
debounceTime(500), | ||
switchMap((user) => this.userService.save(user)), | ||
), | ||
); | ||
} | ||
``` |