Skip to content

Commit

Permalink
Avoid mutation when remapping downloads and favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Oct 16, 2024
1 parent 2a4e2c8 commit 8efdb52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions packages/app/app/actions/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ export const clearFinishedDownloads = createStandardAction(DownloadActionTypes.C
*/
function getDownloadsBackwardsCompatible(): Download[] {
const downloads: Download[] = store.get('downloads');
return downloads.map(download => {
download.track = rewriteTrackArtists(download.track);
return download;
});
return downloads.map(download => ({
...download,
track: rewriteTrackArtists(download.track)
}));
}

export const resumeDownloads = createStandardAction(DownloadActionTypes.RESUME_DOWNLOADS).map(
Expand Down
16 changes: 8 additions & 8 deletions packages/app/app/actions/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { areTracksEqualByName, getTrackItem } from '@nuclear/ui';

import { rewriteTrackArtists, safeAddUuid } from './helpers';
import { createStandardAction } from 'typesafe-actions';
import { TrackItem } from '@nuclear/ui/lib/types';

export const READ_FAVORITES = 'READ_FAVORITES';
export const ADD_FAVORITE_TRACK = 'ADD_FAVORITE_TRACK';
Expand Down Expand Up @@ -129,11 +128,12 @@ export function removeFavoriteArtist(artist) {
function getFavoritesBackwardsCompatible() {
const favorites: { albums?: Album[], artists?: Artist[], tracks?: Track[] } = store.get('favorites');

favorites.tracks = favorites.tracks?.map(rewriteTrackArtists);
favorites.albums = favorites.albums?.map(album => {
album.tracklist = album.tracklist?.map(rewriteTrackArtists);
return album;
});

return favorites as any;
return {
...favorites,
tracks: favorites.tracks?.map(rewriteTrackArtists),
albums: favorites.albums?.map(album => ({
...album,
tracklist: album.tracklist?.map(rewriteTrackArtists)
}))
};
}

0 comments on commit 8efdb52

Please sign in to comment.