I am currently utilizing an npm library which contains a class called MapRepository with promise methods for fetching data from the server:
export class MapRepository {
constructor(
readonly globalEvents: MapGlobalEvent,
baseWebApiUrl: string,
readonly userKey: string = null
) {}
getAllRegistry() {
return this.credentialFetch(this.webApi.registry)
.then((res) => res.ok && res.json())
.catch(catchRequestError([]));
}
}
I have the need to extend and overwrite this class by creating a new class CoreReonMapRepository. My goal is to replace promises with RXJS observables using Http client.
export class CoreReonMapRepository extends MapRepository {
constructor(private http: HttpClient) {
super();// I encounter an issue here
}
getAllRegistry(): Observable<any> {}
}
The problem arises when I have to pass parameters in the parent constructor again, even though MapRepository is already loaded in the library. This violates the rule that top modules should not depend on lower-level modules.
How can this be resolved?
Somewhere deep within the core of the library:
this.repository = new MapRepository(
this.globalEvents,
webApiUrl,
this.props.userKey
);