10 - NgRx Introduction

1. Presentation

Presentation: NgRx

https://docs.google.com/presentation/d/1MknPww1MdwzreFvDh086TzqaB5yyQga0PaoRR9bgCXs/edit?usp=sharing

2. Install redux dev tools chrome extension

https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en

3. Simple Counter Demo

a) Make a new empty Angular CLI Project

We will make a simple NgRx demo app first before getting deep into it with Nx which will scaffold out an opinionated abstracted version.

b) Add NgRx to the app

c) Add a counter.reducer.ts fill to a new state folder in the app

d) Register the reducer and NgRx in the App module

e) Add the HTML to the App component

f) Add App component logic

Note: changeDetection: ChangeDetectionStrategy.OnPush to avoid issue with change detection.

g) Adding action creators

At this point we have no strong types for our actions or our state tree, let's fix that.

  • Add a file to the state folder called counter.actions.ts

h) Adding action State interfaces

  • In the top of the reducer file add a CounterState interface and use it as our new action types in the reducer.

i) Add global State interface

This is useful to be able to type your injected store and select state.

j) Use state interface in app component

Last updated