Skip to content

Commit

Permalink
refactor(ui): onPush on favorite module
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux committed Jul 18, 2019
1 parent 5faf06b commit 5948d3e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions ui/src/app/views/favorite/favorite.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
import { Bookmark } from 'app/model/bookmark.model';
import { NavbarProjectData } from 'app/model/navbar.model';
import { UserService } from 'app/service/services.module';
Expand All @@ -10,7 +10,8 @@ import { AutoUnsubscribe } from '../../shared/decorator/autoUnsubscribe';
@Component({
selector: 'app-favorite',
templateUrl: './favorite.component.html',
styleUrls: ['./favorite.component.scss']
styleUrls: ['./favorite.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
@AutoUnsubscribe()
export class FavoriteComponent {
Expand All @@ -24,21 +25,23 @@ export class FavoriteComponent {

constructor(
private _userService: UserService,
private _navbarService: NavbarService
private _navbarService: NavbarService,
private _cd: ChangeDetectorRef
) {
this.loadBookmarks();

this._navbarSub = this._navbarService.getData(true)
.subscribe((data) => {
this.loading = false;
if (Array.isArray(data)) {
let favorites = data.filter((fav) => fav.favorite);
this.projects = data.filter((elt) => elt.type === 'project');
this.workflows = data.filter((elt) => {
return elt.type === 'workflow' &&
!favorites.find((fav) => fav.type === 'workflow' && fav.workflow_name === elt.workflow_name);
});
}
this._cd.markForCheck();
this.loading = false;
if (Array.isArray(data)) {
let favorites = data.filter((fav) => fav.favorite);
this.projects = data.filter((elt) => elt.type === 'project');
this.workflows = data.filter((elt) => {
return elt.type === 'workflow' &&
!favorites.find((fav) => fav.type === 'workflow' && fav.workflow_name === elt.workflow_name);
});
}
});
}

Expand All @@ -47,7 +50,10 @@ export class FavoriteComponent {
this._userService.getBookmarks()
.pipe(
first(),
finalize(() => this.loading = false)
finalize(() => {
this.loading = false;
this._cd.markForCheck();
})
).subscribe((bookmarks) => this.favorites = bookmarks);
}

Expand Down

0 comments on commit 5948d3e

Please sign in to comment.