Skip to content

Commit

Permalink
fix(managers): do not create http client per each manager
Browse files Browse the repository at this point in the history
  • Loading branch information
seth2810 committed Jul 27, 2024
1 parent 26d01c7 commit db009f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
11 changes: 3 additions & 8 deletions src/lib/Manager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { PrivateConfig, SpotifyConfig } from '../interfaces/Config';
import { HttpClient } from './http/HttpManager';

export class Manager {
protected http = new HttpClient(this.config, this.privateConfig);

constructor(
protected config: SpotifyConfig,
protected privateConfig: PrivateConfig
) {}
export abstract class Manager {
// eslint-disable-next-line no-unused-vars
constructor(protected readonly http: HttpClient) {}
}
34 changes: 17 additions & 17 deletions src/lib/SpotifyAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PrivateConfig, SpotifyConfig } from '../interfaces/Config';
import { SpotifyConfig } from '../interfaces/Config';
import { AlbumManager } from './album/AlbumManager';
import { ArtistManager } from './artist/ArtistManager';
import { AudioManager } from './audio/AudioManager';
import { HttpClient } from './http/HttpManager';
import { MeManager } from './me/MeManager';
import { PlaylistManager } from './playlist/PlaylistManager';
import { RecommendationsManager } from './recommendations/RecommendationsManager';
Expand All @@ -28,28 +29,27 @@ export class SpotifyAPI {

playlist: PlaylistManager;

private privateConfig: PrivateConfig = {};

config: SpotifyConfig;

constructor(config: SpotifyConfig) {
this.config = config;
// eslint-disable-next-line deprecation/deprecation
const { acccessToken, ...httpClientConfig } = config;

// TODO: remove for v2
// eslint-disable-next-line deprecation/deprecation
if (!this.config.accessToken && config.acccessToken) {
// eslint-disable-next-line deprecation/deprecation
this.config.accessToken = config.acccessToken;
if (!httpClientConfig.accessToken && acccessToken) {
httpClientConfig.accessToken = acccessToken;
}

this.tracks = new TrackManager(this.config, this.privateConfig);
this.albums = new AlbumManager(this.config, this.privateConfig);
this.artists = new ArtistManager(this.config, this.privateConfig);
this.users = new UserManager(this.config, this.privateConfig);
this.me = new MeManager(this.config, this.privateConfig);
this.search = new SearchManager(this.config, this.privateConfig);
this.recommendations = new RecommendationsManager(this.config, this.privateConfig);
this.audio = new AudioManager(this.config, this.privateConfig);
this.playlist = new PlaylistManager(this.config, this.privateConfig);
const client = new HttpClient(httpClientConfig, {});

this.tracks = new TrackManager(client);
this.albums = new AlbumManager(client);
this.artists = new ArtistManager(client);
this.users = new UserManager(client);
this.me = new MeManager(client);
this.search = new SearchManager(client);
this.recommendations = new RecommendationsManager(client);
this.audio = new AudioManager(client);
this.playlist = new PlaylistManager(client);
}
}
1 change: 1 addition & 0 deletions src/lib/http/HttpManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class HttpClient {

constructor(
protected config: SpotifyConfig,
// eslint-disable-next-line no-unused-vars
protected privateConfig: PrivateConfig
) {
if (config.http?.baseURL) {
Expand Down

0 comments on commit db009f1

Please sign in to comment.