Implementing a reducer and integrating it with the store

An important concept of Redux is to guard who and what can affect your store. The who is reducers. By allowing only reducers to affect your store, we are more in control of what happens. A simple reducer is just a function that takes a state and action as parameters and is able to produce a new state based on the old state and existing state, like so:

// example reducerfunction countReducer(state = 0, action) {  switch(action.type) {    case "INCREMENT":      return state + 1;    default:      return state;  }}let state = countReducer(0, { type: "INCREMENT" });// 1state = countReducer(state, { type: "INCREMENT" });// 2

So, where does a reducer come into the picture in Redux? Well, the state of the store ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.