Guest User

Untitled

a guest
Oct 21st, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. export class AuthApplicationService {
  2.  
  3. // inject all needed services
  4. constructor(
  5. private sessionService: SessionService,
  6. private authService: AuthService
  7. ) {}
  8.  
  9. // orchestrate multi service execution
  10. // note that subscription and cancelation are responsibility of the caller
  11. login(username: string, password: string): Observable<boolean> {
  12. return this.authService.login(username, password) // returns Observable<User>
  13. .do(user => this.sessionService.setUser(user)) // .do() to perform side-effects, mutate model (sync)
  14. .mapTo(true); // return boolean flag
  15. .catch(err => this.sessionService.setUser(null)); // handle failure, mutate model (sync)
  16. }
  17.  
  18. /* ... */
  19. }
Add Comment
Please, Sign In to add comment