Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. this.items.forEach(element => {
  2. console.log("Note UserId ", element.UserId);
  3. this.userService.loadByUserId(element.UserId).subscribe(res => element.Name = res.Name);
  4. });
  5.  
  6. loadByUserId(userId: string): Observable<any> {
  7. //TODO: Figure better way to check for cached users with multiple async calls at once
  8. if (userId) {
  9. if (this.pendingUsers.filter(f => f == userId).length == 0) {
  10. this.pendingUsers.push(userId);
  11. if (this.users.find(x => x.UserId === userId)) {
  12. const source = Observable.from(this.users);
  13. return source.find(f => f.UserId === userId);
  14. } else {
  15. return this._api.get('User/' + userId).map(res => {
  16. if (this.users.filter(f => f.UserId == res.UserId).length == 0) {
  17. console.log("added user ", res.Name);
  18. this.users.push(res);
  19. }
  20. return res;
  21. });
  22. }
  23. }
  24. else {
  25. return Observable.empty();
  26. }
  27. } else {
  28. return Observable.empty();
  29. }
  30. }
Add Comment
Please, Sign In to add comment