Medium
The example below shows us what practice under RxJS?
const request = interval(1000);
function takeOnlyPairAndSum(
max: number
): UnaryFunction<Observable<number>, Observable<number>> {
return pipe(
filter((val) => val % 2 == 0),
reduce((acc, value) => acc + value),
tap(x => console.log(x)),
);
}
request.pipe(takeOnlyPairAndSum(10)).subscribe();
Author: Amine BouchamStatus: PublishedQuestion passed 16 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!
Similar QuestionsMore questions about RxJS
0
Explain the difference between a Subject and a BehaviorSubject in RxJS0
Why use RxJS ?0
Why is it important to unsubscribe in RxJS?0
Is it important to use unsubscribe on the forkJoin operator?0
How is this way of doing called?
```ts
interface UserData {
[key: string]: any;
}
class UserDataService {
private userData: BehaviorSubject<UserData> = new BehaviorSubject({});
private userData$: Observable<UserData> = this.userData.asObservable();
public setUserData(userData: UserData) {
this.userData.next(userData);
}
public getUserData(): Observable<UserData> {
return this.userData$;
}
public getUserDataByKey(key: string) {
return this.userData$.pipe(map((userData) => userData[key]));
}
}
```