Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class AuthApplicationService {
- // inject all needed services
- constructor(
- private sessionService: SessionService,
- private authService: AuthService
- ) {}
- // orchestrate multi service execution
- // note that subscription and cancelation are responsibility of the caller
- login(username: string, password: string): Observable<boolean> {
- return this.authService.login(username, password) // returns Observable<User>
- .do(user => this.sessionService.setUser(user)) // .do() to perform side-effects, mutate model (sync)
- .mapTo(true); // return boolean flag
- .catch(err => this.sessionService.setUser(null)); // handle failure, mutate model (sync)
- }
- /* ... */
- }
Add Comment
Please, Sign In to add comment