diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index 1ace13f9b..9232a63c8 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -20,6 +20,7 @@ export class ElectronServiceStub { ipcRenderer = { send: jest.fn(), on: jest.fn(), + removeAllListeners: jest.fn(), }; remote = { process: { diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 87506fda6..38cc1d031 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -135,13 +135,15 @@ export class HomeComponent { * @param playlist playlist object */ setPlaylist(playlist: Playlist): void { - this.channelStore.reset(); + this.channelStore.remove(); const favorites = playlist.favorites || []; const channels = playlist.playlist.items.map((element) => createChannel(element) ); this.channelStore.upsertMany(channels); - this.channelStore.update(() => ({ + this.channelStore.update((store) => ({ + ...store, + active: undefined, favorites, playlistId: playlist.id, })); @@ -190,4 +192,13 @@ export class HomeComponent { duration, }); } + + /** + * Remove ipcRenderer listeners after component destroy + */ + ngOnDestroy(): void { + this.commandsList.forEach((command) => + this.electronService.ipcRenderer.removeAllListeners(command.id) + ); + } }