From the course: Learning NgRx
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reducers in NgRx
- [Instructor] So now our actions are basically ready at this point. They're ready to go, and the only step missing for us is to actually use them. So what we're going to do is move to our reducer function, and in our reducer function, we want to be able to handle these two different actions. So first we're gonna add a case for the AddZipcode action. So that's what I do here. I'm importing the zip code action types from our actions file up there, so my IDE did that for me automatically, and now I can just handle that case here. And what I'm going to do is return a new state. So we want to change a state, and first we create a copy of the old state, so what this statement does at this point is it takes the old state, creates a new object with the old state copied into it. And then in here, we want to add our new zip code. So our state has a zip codes property where we want to first copy all of the other zip codes, if any. So using the same array spread syntax with the three dots, now…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Describing state with NgRx5m
-
(Locked)
Actions with NgRx3m 51s
-
(Locked)
Reducers in NgRx5m 56s
-
(Locked)
The NgRx store: Dispatch an action2m 57s
-
(Locked)
The NgRx store: Listen to state updates3m 43s
-
(Locked)
Set up effects for asynchronous tasks3m 16s
-
(Locked)
Implementation of effects4m 36s
-
(Locked)
Challenge: Complete the code in the project to remove a zip code from the list52s
-
(Locked)
Solution: Source code with comments1m 24s
-
-
-
-