Book Image

Architecting Angular Applications with Redux, RxJS, and NgRx

By : Christoffer Noring
Book Image

Architecting Angular Applications with Redux, RxJS, and NgRx

By: Christoffer Noring

Overview of this book

Managing the state of large-scale web applications is a highly challenging task with the need to align different components, backends, and web workers harmoniously. When it comes to Angular, you can use NgRx, which combines the simplicity of Redux with the reactive programming power of RxJS to build your application architecture, making your code elegant and easy to reason about, debug, and test. In this book, we start by looking at the different ways of architecting Angular applications and some of the patterns that are involved in it. This will be followed by a discussion on one-way data flow, the Flux pattern, and the origin of Redux. The book introduces you to declarative programming or, more precisely, functional programming and talks about its advantages. We then move on to the reactive programming paradigm. Reactive programming is a concept heavily used in Angular and is at the core of NgRx. Later, we look at RxJS, as a library and master it. We thoroughly describe how Redux works and how to implement it from scratch. The two last chapters of the book cover everything NgRx has to offer in terms of core functionality and supporting libraries, including how to build a micro implementation of NgRx. This book will empower you to not only use Redux and NgRx to the fullest, but also feel confident in building your own version, should you need it.
Table of Contents (12 chapters)

What this book covers

Chapter 1, Quick Look Back at Data Services for Simple Apps, covers how to work with services and how Angular dependency injection helps out. It also brings up the MVC pattern and discusses cohesion and coupling.

Chapter 2, 1.21 Gigawatt – Flux Pattern Explained, teaches what the Flux pattern is and what concepts it consists of. It shows how to implement the Flux pattern using stores, a dispatcher, and several views.

Chapter 3, Asynchronous Programming, looks at what asynchronous means and talks about callbacks, promises, async/await, and how the async library can help us create order in our asynchronous code.

Chapter 4, Functional Reactive Programming, compares declarative and imperative programming and looks at a subset of declarative programming, functional programming. We drill down into certain properties of functional programming, such as higher-order functions, immutability, and recursion. Furthermore, we look at how to make code reactive and what reactive means.

Chapter 5, RxJS Basics, introduces the RxJS library. Furthermore, it brings up concepts such as Observable, Producer, and Observer. It further discusses how the Observable is the asynchronous concept that we need to unify all our asynchronous concepts into one. We also touch on operators and what they are. Lastly, we attempt to build our own micro implementation of RxJS to further understand what's going on under the hood.

Chapter 6, Manipulating Stream and Their Values, focuses a lot on educating the reader on operators, the thing that gives RxJS its power. The reader should leave this chapter with a lot more knowledge about how to manipulate data as well as Observables.

Chapter 7, RxJS Advanced, goes deeper and tries to explain more advanced concepts in RxJS, such as hot and cold Observables, subjects, error handling, and how to test your RxJS code with Marble testing.

Chapter 8, Redux, demonstrates the Redux pattern and explains how it came from the Flux pattern and improved upon some of its paradigms and concepts. The reader will learn how it works in practice by learning to build their own Redux and also using the same, involving a couple of views.

Chapter 9, NgRx – Reduxing that Angular App, explores what NgRx is and what it consists of. It also shows the reader how to put it in to use by adding it to an Angular application. Concepts such as store are explained and demoed, and the reader will learn how to debug and handle side effects with the Effects library.

Chapter 10, NgRx – In Depth, covers the Entity library, which allows you to write way less code by reducing a lot of boilerplate. It also shows how you can put a router's state in the store. Furthermore, we look at how to test NgRx, how to build it yourself, and lastly, we cover Schematics, which will help us further by allowing us to scaffold the most common constructs we need to work with in NgRx.