All posts

3 min read

  • angular
  • ngrx

Why every page here has its own NgRx facade

A short tour of the store layout behind this site: page actions, API actions and a facade in front of them.

Each page of this site that talks to a backend owns a small feature store. The layout is always the same:

  • Page actions describe what happened in the UI, for example Page Enter.
  • API actions describe what came back: a success or a failure.
  • A facade is the only thing a component talks to.

What the facade buys you

Components stay free of selectors and dispatch calls, so changing how the data is loaded does not touch a single template. This blog is a good example: it can read posts from an API or from JSON files, and the components do not know which.

get postList$(): Observable<PostDto[]> {
  return this.store$.select(BlogListSelectors.entries);
}