Last active
December 28, 2019 17:03
-
-
Save ThomasBurleson/d245aba022646bc28223fbb46cdd5e76 to your computer and use it in GitHub Desktop.
Compressing View Logic with Facades
This file contains hidden or 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
/** | |
* | |
* Snippet from blog article: https://auth0.com/blog/ngrx-facades-pros-and-cons/ | |
* | |
*/ | |
@Component({ | |
selector: 'abl-books-page', | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
template: ` | |
<mat-card> | |
<mat-card-title>My Collection</mat-card-title> | |
<mat-card-actions> | |
<button mat-button raised color="accent" (click)="logout()">Logout</button> | |
</mat-card-actions> | |
</mat-card> | |
<abl-book-preview-list [books]="books$ | async"></abl-book-preview-list> | |
}) | |
export class BooksPageComponent implements OnInit { | |
books$: Observable<Book[]>; | |
constructor(private booksFacade: BooksFacadeService) { | |
this.books$ = booksFacade.allBooks$; | |
} | |
ngOnInit() { | |
this.booksFacade.dispatch(new BooksPageActions.Load()); | |
} | |
} | |
I would've done
export class BooksPageComponent {
constructor(public facade: BooksFacadeService) { }
}
and
<abl-book-preview-list [books]="facade.allBooks$ | async"></abl-book-preview-list>
Even simpler! Thanks for bringing us this awesome pattern, Thomas!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vs
How is it any different other than another layer of
BooksFacadeService
which literally does the same thing.View components never know about the complexity behind selectors as well - they just consume them.
Selectors
are already the abstraction and encapsulation layer.