refactor: remove ipcRenderer listeners on destroy

This commit is contained in:
4gray committed 2021-01-05 00:53:41 +01:00
1 parent 5a31791b21
commit 312d2e76d4
2 files changed
+14 -2

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ export class ElectronServiceStub {
ipcRenderer = {
send: jest.fn(),
on: jest.fn(),
removeAllListeners: jest.fn(),
};
remote = {
process: {
+13 -2
View File
@@ -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)
);
}
}