Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Dev #1

wants to merge 4 commits into from

Conversation

Madi-Naf
Copy link

No description provided.

Copy link
Owner

@yatho yatho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci d'avoir proposer une solution. Essai quand tu peux d'éviter de modifier des variables intermédiaires. Dans l 'état actuel des choses il faut que tu gères le unsubscribe. Avec le pipe async cette partie est délégué au pipe.

template: `
<h2> Exercice 1 </h2>
<div style="display: flex;">
@for (number of numbers; track number) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi passer par une variable intermédiaire alors qu'on a l'observable et le pipe async ?

this._numbers$
// TODO : Emettre uniquement les valeurs pairs
// TODO : Multiplier chaque valeur de l'observable par 2
.pipe(take(10), map(nb => 2*nb))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

À quoi sert le take(10) dans ce cas de figure ?

next: (nb: number) => {
// TODO : Affiche le résultat dans la console et dans le template
console.log(nb)
this.numbers.push(nb)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On peut se passer de cette variable


// TODO : Créer un observable qui émet une séquence de nombre de 1 à 10
private _numbers$ = range(1, 10)
numbers: Array<number> = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On peut se passer de cette variable intermédiaire

this._numbers$
.subscribe({
next: id => {
getFromId(id).subscribe({ // !REVIEW use switch map instead
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui c'est ça switchMap est l'opérateur qu'il te faut

ngOnInit(): void {
console.log('---------------- exercice 2 ----------------')
this._numbers$
.subscribe({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L'idée est de maximiser l'usage des operator xrjs. Je t'invite donc à réécrire ton code dans ce sens.

// TODO : Afficher uniquement les 10 premières valeurs émises par le nouvel observable


private _combined$ = combineLatest([this._lettreA$, this._lettreZ]).pipe(map(([nb1, nb2]) => [nb1, nb2]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

À quoi sert le map à la fin de la ligne ?


private _combined$ = combineLatest([this._lettreA$, this._lettreZ]).pipe(map(([nb1, nb2]) => [nb1, nb2]))
tuples: Array<string []> = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encore une variable intermédiaire inutile

// TODO : Utiliser un interval pour émettre des valeurs
// TODO : Utiliser un opérateur pour limiter le nombre de valeurs émises à 10
// TODO : Utiliser un opérateur pour limiter les valeurs émises en fonction d'une condition
_count: number = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cette variable compte, mais interval(x) compte également. la variable est donc inutile.

// TODO : Utiliser un opérateur pour émettre les 5 dernières valeurs


result: Array<number> = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable inutile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants