Skip to content

Commit

Permalink
refactor: simplify DataFactory and PwaService dependencies
Browse files Browse the repository at this point in the history
Remove unnecessary parameters from DataFactory and PwaService 
constructor. The changes streamline the service initialization 
process by eliminating the unused HttpClient dependency in 
DataFactory and adjusting PwaService to inject HttpClient 
directly. This improves code clarity and reduces complexity.
  • Loading branch information
4gray committed Nov 28, 2024
1 parent 25875bf commit 5a7d255
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
7 changes: 2 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ function isTauri() {
/**
* Conditionally imports the necessary service based on the current environment
*/
export function DataFactory(
ngxIndexedDBService: NgxIndexedDBService,
http: HttpClient
) {
export function DataFactory() {
if (isElectron()) {
return new ElectronService();
}
if (isTauri()) {
return new TauriService();
}
return new PwaService(http);
return new PwaService();
}

@NgModule({
Expand Down
16 changes: 7 additions & 9 deletions src/app/services/pwa.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { ApplicationRef, inject, Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SwUpdate } from '@angular/service-worker';
import { Store } from '@ngrx/store';
Expand All @@ -19,23 +19,21 @@ import { Playlist } from '../../../shared/playlist.interface';
import { AppConfig } from '../../environments/environment';
import * as PlaylistActions from '../state/actions';
import { DataService } from './data.service';
import { PlaylistsService } from './playlists.service';

@Injectable({
providedIn: 'root',
})
export class PwaService extends DataService {
appRef = inject(ApplicationRef);
playlistService = inject(PlaylistsService);
snackBar = inject(MatSnackBar);
store = inject(Store);
swUpdate = inject(SwUpdate);
translateService = inject(TranslateService);
private readonly http = inject(HttpClient);
private readonly snackBar = inject(MatSnackBar);
private readonly store = inject(Store);
private readonly swUpdate = inject(SwUpdate);
private readonly translateService = inject(TranslateService);

/** Proxy URL to avoid CORS issues */
corsProxyUrl = AppConfig.BACKEND_URL;

constructor(private http: HttpClient) {
constructor() {
super();
console.log('PWA service initialized...');
}
Expand Down

0 comments on commit 5a7d255

Please sign in to comment.