From the course: Angular State Management with NgRx
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Core concepts: Reducers and store - Angular Tutorial
From the course: Angular State Management with NgRx
Core concepts: Reducers and store
- [Instructor] Welcome to this video, where I'm going to talk about reducer and store, two more of the core concepts of Redux and NgRx. We saw earlier that the state gets updated through actions. Reducers are the function that makes the transition happen. As a result, a reducer is a pure function that takes a current state and an action as a parameter and then returns a brand new state object. It's important to know that a new state is an updated copy of the old one, as getting a new reference helps with change detection in most JavaScript frameworks. Also reducers only performs synchronous state changes. We'll see later another kind of feature called effect is used for asynchronous changes. Here is a simple example of reducer. Let's go for it line by line. First, a reducer is a function. Its first parameter is the current state, and if none is passed, we use the initial state of the application as a default. Then we pass the action that we want to perform. Most reducers would have…