-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add service locator * chore: fix build issue --------- Co-authored-by: Dzianis Dashkevich <[email protected]>
- Loading branch information
1 parent
4558ca0
commit a9b5047
Showing
12 changed files
with
164 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Interfaces: | ||
import type { ILogger } from './types/logger.declarations'; | ||
import type { LoggerDependencies } from './utils/logger'; | ||
import type { IInterceptorsStorage } from './types/interceptors.declarations'; | ||
import type { PlayerConfiguration } from './types/configuration.declarations'; | ||
import type { IStore } from './types/store.declarations'; | ||
import type { IEventEmitter } from './types/eventEmitter.declarations'; | ||
import type { EventTypeToEventMap } from './types/eventTypeToEventMap.declarations'; | ||
import type { IEnvCapabilitiesProvider } from './types/envCapabilities.declarations'; | ||
import type { INetworkManager } from './types/network.declarations'; | ||
import type { InterceptorTypeToInterceptorMap } from './types/interceptorTypeToInterceptorMap.declarations'; | ||
import type { NetworkManagerDependencies } from './network/networkManager'; | ||
|
||
// Implementations | ||
import { Logger } from './utils/logger'; | ||
import { InterceptorsStorage } from './utils/interceptorsStorage'; | ||
import { ConfigurationManager } from './configuration/configurationManager'; | ||
import { EventEmitter } from './utils/eventEmitter'; | ||
import { EnvCapabilitiesProvider } from './utils/envCapabilities'; | ||
import { NetworkManager } from './network/networkManager'; | ||
import { InterceptorType } from './consts/interceptorType'; | ||
|
||
export class ServiceLocator { | ||
public readonly logger: ILogger; | ||
public readonly interceptorsStorage: IInterceptorsStorage; | ||
public readonly configurationManager: IStore<PlayerConfiguration>; | ||
public readonly eventEmitter: IEventEmitter<EventTypeToEventMap>; | ||
public readonly envCapabilitiesProvider: IEnvCapabilitiesProvider; | ||
public readonly networkManager: INetworkManager; | ||
|
||
public constructor() { | ||
const { console } = window; | ||
|
||
this.configurationManager = this.createConfigurationManager_(); | ||
|
||
const configuration = this.configurationManager.getSnapshot(); | ||
|
||
this.logger = this.createLogger_({ console, label: 'Player', delimiter: '>' }); | ||
|
||
this.interceptorsStorage = this.createInterceptorsStorage_(); | ||
this.eventEmitter = this.createEventEmitter_(); | ||
this.envCapabilitiesProvider = this.createEnvCapabilitiesProvider_(); | ||
this.networkManager = this.createNetworkManager_({ | ||
logger: this.logger.createSubLogger('NetworkManager'), | ||
eventEmitter: this.eventEmitter, | ||
configuration: configuration.network, | ||
networkInterceptorsProvider: { | ||
getNetworkRequestInterceptors: (): Set<InterceptorTypeToInterceptorMap[InterceptorType.NetworkRequest]> => | ||
this.interceptorsStorage.getInterceptorsSet(InterceptorType.NetworkRequest), | ||
}, | ||
}); | ||
} | ||
|
||
protected createLogger_(dependencies: LoggerDependencies): ILogger { | ||
return new Logger(dependencies); | ||
} | ||
|
||
protected createInterceptorsStorage_(): IInterceptorsStorage { | ||
return new InterceptorsStorage(); | ||
} | ||
|
||
protected createConfigurationManager_(): IStore<PlayerConfiguration> { | ||
return new ConfigurationManager(); | ||
} | ||
|
||
protected createEventEmitter_(): IEventEmitter<EventTypeToEventMap> { | ||
return new EventEmitter<EventTypeToEventMap>(); | ||
} | ||
|
||
protected createEnvCapabilitiesProvider_(): IEnvCapabilitiesProvider { | ||
return new EnvCapabilitiesProvider(); | ||
} | ||
|
||
protected createNetworkManager_(dependencies: NetworkManagerDependencies): INetworkManager { | ||
return new NetworkManager(dependencies); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/playback/src/lib/types/interceptors.declarations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { InterceptorType } from '../consts/interceptorType'; | ||
import type { InterceptorTypeToInterceptorMap } from './interceptorTypeToInterceptorMap.declarations'; | ||
|
||
export interface IInterceptorsStorage { | ||
addInterceptor<K extends InterceptorType>(interceptorType: K, interceptor: InterceptorTypeToInterceptorMap[K]): void; | ||
removeInterceptor<K extends InterceptorType>( | ||
interceptorType: K, | ||
interceptor: InterceptorTypeToInterceptorMap[K] | ||
): void; | ||
getInterceptorsSet<K extends InterceptorType>(interceptorType: K): Set<InterceptorTypeToInterceptorMap[K]>; | ||
removeAllInterceptorsForType<K extends InterceptorType>(interceptorType: K): void; | ||
removeAllInterceptors(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.