Skip to content

Instantly share code, notes, and snippets.

@nartc
Created March 29, 2020 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nartc/63dba555ba40fa9ca4fb8d5d89a77fac to your computer and use it in GitHub Desktop.
Save nartc/63dba555ba40fa9ca4fb8d5d89a77fac to your computer and use it in GitHub Desktop.
// API Service
export class ApiService {
get(parameters: SomeParameters): Observable<ReturnType> {
if (!this.validate(parameters)) {
// throw error on failed validation
throw new Error('Parameters do not pass validation');
}
return this.httpClient.get(...);
}
getOther(parameters: SomeParameters): Observable<ReturnType> {
if (!this.validate(parameters)) {
// throw error on failed validation
throw new Error('Parameters do not pass validation');
}
return this.httpClient.get(...);
}
}
// SomeOtherService
export class SomeOtherService {
someFlag: boolean;
constructor(private apiService: ApiService) {}
getSome(someParameters: SomeParameters): Observable<Some> {
return iif(() => this.someFlag, this.apiService.get(someParameters), this.apiService.getOther(someParameters));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment