-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Dev #1
Conversation
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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> = [] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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])) |
There was a problem hiding this comment.
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 []> = [] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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> = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable inutile
No description provided.