Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Architecting Angular Applications with Redux, RxJS, and NgRx
Architecting Angular Applications with Redux, RxJS, and NgRx

Architecting Angular Applications with Redux, RxJS, and NgRx: Learn to build Redux style high-performing applications with Angular 6

eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Architecting Angular Applications with Redux, RxJS, and NgRx

1.21 Gigawatt – Flux Pattern Explained

Let's first off explain our title. What do we mean by 1.21 Gigawatt? I'm going to quote the character Doc Brown from the movie Back to the Future (http://www.imdb.com/name/nm0000502/?ref_=tt_trv_qu):

"Marty, I'm sorry, but the only power source capable of generating 1.21 gigawatts of electricity is a bolt of lightning."

Why are we talking about the movie Back to the Future? This is where the name Flux comes from. It's time for another quote from the same movie:

"Yes! Of course! November 5, 1955! That was the day I invented time-travel. I remember it vividly. I was standing on the edge of my toilet hanging a clock, the porcelain was wet, I slipped, hit my head on the sink, and when I came to I had a revelation! A vision! A picture in my head! A picture of this! This is what makes time travel possible...

Core concepts overview

At the core of the Flux pattern is a unidirectional data flow. It uses some core concepts to achieve this flow. The main idea is when an event is created on a UI, through the interaction of a user, an action is created. This action consists of an intent and a payload. The intent is what your are trying to achieve. Think of the intent as a verb. Add an item, remove an item, and so on. The payload is the data change that needs to happen to achieve our intent. If we are trying to add an item, then the payload is the newly created item. The action is then propagated in the flow with the help of a dispatcher. The action and its data eventually end up in a store.

The concepts that make up the Flux pattern are:

  • Action and action creators, where we set up an intention and a payload of data
  • The dispatcher, our spider in the web that is able to send messages left...

A uniform data flow

Let's introduce all parties involved in our uniform data flow by starting from the very top and slowly work our way down, concept by concept. We will build an application consisting of two views. In the first view, the user will select an item from a list. This should result in an action being created. This action will then be dispatched, by the dispatcher. The action and its payload will end up in a store. The other view meanwhile listens to changes from the store. When an item is selected, the second view will be made aware and can therefore indicate in its UI that a specific item has been selected. On a high level, our application and its flow will look like the following:

Action – capture the intent

...

Demoing a uniform data flow

Ok, so we have described the parts our application consists of:

  • A view where a user is able to select an index
  • A dispatcher that allows us to send a message
  • A store that contains our selected index
  • A second view where the selected index is read from the store

Let's build a real app from all of this. The following code is found in the code repository under Chapter2/demo.

Creating a selection view

First off we need our view in which we will perform the selection:

// demo/selectionView.js

import dispatcher from "./dispatcher";

console.log('selection view loaded');

class SelectionView {
selectIndex(index) {
console.log('selected index ', index);
dispatcher.dispatch...

Adding more actions to our flow

Let's do a reality check here. We haven't built the Flux flow as prettily as we could make it. The overall picture is correct but it'd be nice if we can clean it up a bit to make room for more actions so we get a real sense of how the application should grow from here.

Cleaning up the view

The first order of business is to have a look at our first view and how it reacts to user interactions. It looks like this currently:

// first.view.js

import dispatcher from "./dispatcher";

class FirstView {
selectIndex(index) {
dispatcher.dispatch({
type: "SELECT_INDEX",
data: index
});
}
}

let view = new FirstView();

Adding a few more actions into the mix...

Adding AJAX calls

So far, we have only been dealing with static data in our Flux flow. The time has now come to add real data connections to the flow and thereby real data. It is time to start talking to APIs through AJAX and HTTP. Fetching data is quite easy nowadays, thanks to the fetch API and libraries such as RxJS. What you need to think about when incorporating it in the flow is:

  • Where to place the HTTP call
  • How to ensure that the store is updated and interested views are notified

We have a point at which we register the store to the dispatcher, with this piece of code:

// excerpt from store-actions-immutable.js

const createProduct = (product) => {
if (!store["products"]) {
store["products"] = [];
}

store.products = [...store.products, Object.assign(product)];
}

dispatcher.register(({ type, data }) => {
switch (type) {
case CREATE_PRODUCT...

An even bigger solution

So far, we have been describing a solution that consists of only a product's topic and communication has only taken place from one view to another. In a more realistic application, we would have a lot of topics such as user management, orders, and so on; exactly what they are called is dependent on the domain of your application. As for views, it is quite possible that you will have a ton of views listening to another view, as in this example:

This describes an application that contains four different view components around their own topic. The Customers view contains a list of customers and it allows us to alter which customer we currently want to focus on. The other three supporting views show Orders, Messages, and Friends and their content depends on which customer is currently highlighted. From a Flux standpoint, the Orders, Messages, and Friends...

Summary

We set out trying only to explain the Flux architecture pattern. It would have been very easy to start mentioning how it fits with React and how there are nice libraries and tools that support Flux and React. That would, however, have taken our focus away from explaining the pattern from a more framework-agnostic viewpoint. Therefore, the rest of this chapter set out to explain core concepts such as actions, action creator, dispatcher, store, and uniform data flow. Little by little, we improved the code to start using constants, action creators, and a nice supporting library such as EventEmitter. We explained how HTTP fits into this and, lastly, we discussed how we could build out our application. There is a lot more that can be said about Flux, but we chose to limit the scope to understanding the fundamentals so we can compare its approach as we dive into Redux and NgRx...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • - Learn what makes an excellent Angular application architecture
  • - Use Redux to write performant, consistent Angular applications
  • - Incorporate Reactive Programming principles and RxJS to make it easier to develop, test, and debug your Angular applications

Description

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.

Who is this book for?

If you have been developing Angular applications and want to dive deeper into the Angular architecture with Redux, RxJS, and NgRx to write robust web apps, then this book is for you.

What you will learn

  • • Understand the one-way data flow and Flux pattern
  • • Work with functional programming and asynchronous data streams
  • • Figure out how RxJS can help us address the flaws in promises
  • • Set up different versions of cascading calls
  • • Explore advanced operators
  • • Get familiar with the Redux pattern and its principles
  • • Test and debug different features of your application
  • • Build your own lightweight app using Flux, Redux, and NgRx

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 26, 2018
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781787121751
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Mar 26, 2018
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781787121751
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
Architecting Angular Applications with Redux, RxJS, and NgRx
$48.99
Angular Design Patterns
$32.99
Angular 6 for Enterprise-Ready Web Applications
$54.99
Total $ 136.97 Stars icon

Table of Contents

11 Chapters
Quick Look Back at Data Services for Simple Apps Chevron down icon Chevron up icon
1.21 Gigawatt – Flux Pattern Explained Chevron down icon Chevron up icon
Asynchronous Programming Chevron down icon Chevron up icon
Functional Reactive Programming Chevron down icon Chevron up icon
RxJS Basics Chevron down icon Chevron up icon
Manipulating Streams and Their Values Chevron down icon Chevron up icon
RxJS Advanced Chevron down icon Chevron up icon
Redux Chevron down icon Chevron up icon
NgRx – Reduxing that Angular App Chevron down icon Chevron up icon
NgRx – In Depth Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(10 Ratings)
5 star 50%
4 star 10%
3 star 10%
2 star 20%
1 star 10%
Filter icon Filter
Top Reviews

Filter reviews by




Juan C. Aug 08, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is not for the newbies, however I have been learning Angular for a couple of months and now I feel quite comfortable reading the book. It has a few errors which are small. Better than the overpriced course by Todd Motto. You may combine this book with the Angular course by Brad Traversy and the Angular 5 free e-book by Asim Hussain and you are ready to learn lots of Angular.
Amazon Verified review Amazon
Chetan Munegowda May 27, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I would definitely recommend this book if you are a Angular developer!!
Amazon Verified review Amazon
Paulo Diaz May 05, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book has an excellent approach about the angular and the framework with good explain and samples.
Amazon Verified review Amazon
Oscar Lagatta Apr 09, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent must read for Angular Developers.
Amazon Verified review Amazon
Danny Yu Oct 21, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was initially confused by the way the author structured the chapters. Many pages spent on the inner-workings of the redux store. It becomes clear around chapter 7/8, when the subject of producers comes up again. If you've written an angular app + done some reading on ngrx/redux before, then the first 8 chapters will just be a lengthy review. The final 3 chapters helped put everything together and also covered best-practices. Well written & easy to read.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.