Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
Reactive programming with Angular and ngrx : learn to harness the power of reactive programming with RxJS and ngrx extensions
Farhi O., Apress, New York, NY, 2017. 148 pp. Type: Book (978-1-484226-19-3)
Date Reviewed: Nov 9 2017

Many programmers may not be aware of the fact that JavaScript has a powerful functional programming subset. The use of callbacks is very common, but is only a small part of how functional techniques can improve the conciseness, readability, and maintainability of JavaScript programs.

In his 1977 Turing Award lecture, John Backus advocated the use of functional programming instead of the “von Neumann style,” which relies heavily on state changes and is therefore highly dependent on time. Functional programming, in contrast, is based on the definition of mathematical transformations and transcends time. This makes it particularly useful for asynchronous programs, which are increasingly prevalent. This has led to the incorporation of functional techniques in modern programming languages and frameworks. In particular, streams are a functional abstraction of sequences of values (such as the values a variable takes over time, or sequences of mouse clicks) as first-class values. This allows programmers to write straight-line code for computations that would normally require loops. In an asynchronous context, this abstraction replaces deeply nested callbacks and complex coordination code.

The reactive extensions (ReactiveX) framework combines the stream abstraction with the Observer pattern. RxJS is the version for JavaScript, and ngrx builds on top of RxJS to support Angular. This book illustrates the effective use of ngrx to develop modular Angular applications, using a series of steps in the development of a viewer for YouTube videos.

Following a short introduction, the second chapter presents the first version of the application, which is almost all boilerplate. Then, chapter 3 extends the code with state management. This is the most paradoxical part of functional programming, which abhors state changes. The paradox is resolved by defining the store as a stream of all the states the application goes through. Subscribers to the store are synchronized with its “current” value; this allows subscribers to be written independently, yet influence each other by posting actions to the store. The application code can therefore consist of pure functions, without side effects. The store itself is defined by means of “reducers,” each of which takes part of the state and an action (a data structure), and returns a new value for that part.

Following two chapters that discuss presentational and container components and services, chapter 6 refactors the code to use so-called side effects. These are chain reactions that are triggered by actions and can create new actions. This leads to very concise, elegant, and modular code, which replaces reams of nested callback functions in non-functional styles. The book closes with a description of reactive forms and some best practices.

Because of the lack of side effects in functional programming, it is particularly easy to write test cases, mocking parts of the application that are not being tested. Furthermore, “time travel” over the execution history becomes possible, even changing values to see the resulting effects. One of the nice features of the book is that it demonstrates how to write test cases and how to refactor them when the code changes.

The code is written in TypeScript, a typed extension of JavaScript designed for scale. This is a natural choice, since Angular itself has been converted to TypeScript, and makes the code more readable.

Given that the code examples are the heart of this book, it is unfortunate that the code in the publisher’s website doesn’t work with the newest version of Node.js (and is also different in places from the code shown in the book). I spent several hours trying to run the boilerplate code of chapter 2 by tweaking the installation dependencies, without success.

In order to study the code in the book, the reader needs to know JavaScript, TypeScript, Angular, RxJS, and ngrx. An advanced book like this obviously doesn’t need to start from the basics of the programming language, and even knowledge of Angular could be assumed. However, the book doesn’t explain the basic functions of RxJS, leaving the reader to look up their documentation. Since the book is quite small, I feel that it could appeal to a much larger audience by adding a short explanation of the relevant features of TypeScript and the more advanced features of Angular used in the text, as well as a more detailed introduction to the philosophy and functions of RxJS. As it stands, the book can be used very effectively as a tutorial to ngrx by working through the series of enhancements and refactorings, but is not a self-contained introduction to RxJS and ngrx.

More reviews about this item: Amazon

Reviewer:  Yishai Feldman Review #: CR145651 (1802-0040)
Bookmark and Share
  Reviewer Selected
Featured Reviewer
 
 
Object-Oriented Programming (D.1.5 )
 
 
Javascript (D.3.2 ... )
 
 
World Wide Web (WWW) (H.3.4 ... )
 
 
Language Classifications (D.3.2 )
 
Would you recommend this review?
yes
no
Other reviews under "Object-Oriented Programming": Date
Object-oriented programming systems, languages, and applications
Paepcke A.  Object-oriented programming systems, languages, and applications,Phoenix, AZ,Oct 6-Oct 11, 1991,1991. Type: Whole Proceedings
Oct 1 1992
Object lifecycles
Shlaer S., Mellor S., Yourdon Press, Upper Saddle River, NJ, 1992. Type: Book (9780136299400)
Apr 1 1993
Object-oriented programming
Voss G., Osborne/McGraw-Hill, Berkeley, CA, 1991. Type: Book (9780078816826)
Oct 1 1992
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy