Skip to content

Instantly share code, notes, and snippets.

@nartc
Created March 29, 2020 15:17
Show Gist options
  • 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