Created
March 29, 2020 15:17
-
-
Save nartc/63dba555ba40fa9ca4fb8d5d89a77fac to your computer and use it in GitHub Desktop.
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
// 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