Before
private readUrlEffect$ = this.route.queryParams.pipe(
map(({ query }) =>
this.searchForm.setValue({ search: !!query ? query ; '' })
)
);
After
private readUrlEffect$ = this.route.queryParams.pipe(
map(({ query }) =>
this.searchForm.setValue({ search: query ?? '' })
)
);
Optional Chaining + Nullish
Before
search(query: string): Observable<any> {
const searchTypes = ['songs', 'albums', 'playlists'];
return from(
this.musicKitInstance.api.search(query, {
types: searchTypes,
limit: 50,
})
).pipe(
map((res: any) => {
return {
albums: res.albums.data,
songs: res.songs.data,
playlists: res.playlists.data,
};
}),
retryWhen((error) => error.pipe(delay(500))),
timeout(5000)
);
}
After
search(query: string): Observable<any> {
const searchTypes = ['songs', 'albums', 'playlists'];
return from(
this.musicKitInstance.api.search(query, {
types: searchTypes,
limit: 50,
})
).pipe(
map((res: any) => ({
albums: res?.albums?.data ?? null,
songs: res?.songs?.data ?? null,
playlists: res?.playlists?.data ?? null,
})),
retryWhen((error) => error.pipe(delay(500))),
timeout(5000)
);
}