Skip to content

Instantly share code, notes, and snippets.

@dev-sampsonorson
Forked from nartc/iif_defer.ts
Created June 14, 2023 08:45
Show Gist options
  • Save dev-sampsonorson/e42145f8684b4caa899980756e32a85e to your computer and use it in GitHub Desktop.
Save dev-sampsonorson/e42145f8684b4caa899980756e32a85e 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