Fireship · @fireship
Angular ngrx Redux Quick Start Tutorial
Uploaded August 29, 2017 · Length 9:01
Summary
This video teaches how to implement Redux with NGRX in an Angular app, covering the basics of Redux and building a simple app from scratch.
- angular ngrx redux tutorial
- ngrx store example
- angular redux implementation
- ngrx store setup
- angular ngrx store
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
Redux is a design pattern that keeps all application data in a single JavaScript object.
- 0:05
This gives you a predictable global data state at any given point in time.
- 0:09
This technique is most popular in React apps, but it can also be applied to Angular apps
- 0:14
with a library called NGRX, which uses Redux principles with RxJS as the underlying library.
- 0:20
In this episode, I'm going to cover the basics of Redux, and then we'll build an Angular
- 0:25
app from scratch using NGRX.
- 0:27
Let's start by looking at the high-level principles of Redux.
- 0:30
So we have a user interface that is displaying some data.
- 0:34
Then the user performs an action that will change the state of the data.
- 0:37
In Redux, the only way to change the state is by dispatching an action.
- 0:42
Once an action has been dispatched, it will go to a reducer function, which will copy
- 0:46
the current state of the application, along with any data changes, to a new JavaScript
- 0:50
object.
- 0:51
It's important to note that the state is immutable, meaning it can't be changed directly.
- 0:55
has to be copied over to a whole brand new state.
- 0:58
The reason for this is it gives us a predictable tree of state changes that we can use to debug
- 1:03
an application, and that's really the main benefit of Redux.
- 1:06
Once the reducer has created the new state, it gets saved in a datastore, which can be
- 1:10
thought of as a client-side database more or less.
- 1:13
In NGRX, we treat this datastore as an observable, so we can subscribe to it from anywhere in
- 1:18
the application.
- 1:19
This means that all of our components and services will be sharing the same data at
- 1:23
any given point in time.
- 1:25
Now let's start building a brand new NGRX app.
- 1:29
First run ng-new and then npm install ngrx slash store.
- 1:33
I'm going to start with the most simple example possible, where our entire application state
- 1:37
is represented by a single string.
- 1:39
Then we'll create two different actions to translate the string into Spanish or French.
- 1:44
First let's go into the app module and import NGRX.
- 1:48
I'm also importing a reducer function which we'll create in the next step.
- 1:52
Then in the imports metadata add storeModuleForRoot and then we'll add a key message with the simple
- 1:58
reducer.
- 1:59
Now let's go ahead and build this reducer function.


