RxJS in Action
Paul P. Daniels and Luis Atencio
  • MEAP began March 2016
  • Publication in May 2017 (estimated)
  • ISBN 9781617293412
  • 400 pages (estimated)
  • printed in black & white

A growing flood of data is aimed at your JavaScript application, and your application needs be ready for it. As more and more data is received, your application must scale to stay operational. There's also the problem of latency when data has to be fetched from remote locations. RxJS, or Reactive Extensions for JavaScript, is a library for transforming, composing, and consuming streams of data. RxJS combines reactive and functional programming to give you an extensible, asynchronous event handling system for JavaScript. RxJS is ideal for applications with features that have continuous data flows that have to fetch and combine multiple pieces of remote data, auto-complete text boxes, drag and drop, process user input, and more.

RxJS in Action gives you the development skills you need to create reactive applications with RxJS. This book is full of theory and practical examples that build on each other and help you begin thinking in a reactive manner. You'll begin by learning the fundamentals of functional programming, and dive in to the basics of RxJS and what it means to be reactive as you gain a working understanding of the concepts involved. Next, you'll learn how to build real-world applications with RxJS by sequencing different types of streams under the Rx computing model. The last part of the book tackles the advanced topics to take your reactive programming skills to the next level, as you'll learn how to deal with error handling, unit testing, and the role of RxJS when combined with frameworks such as Angular.js or Cycle.js . Examples in the book use RxJS 5, the latest version of RxJS built with an eye on performance and simplicity. By the end of this book, you'll be able to transform difficult and clunky asynchronous JavaScript functions into more streamlined, robust, and fluent expressions.

Table of Contents detailed table of contents

Part 1

1. Thinking Reactively

1.1. Synchronous versus asynchronous computing

1.1.1. Issues with blocking code

1.1.2. Non-blocking code with callback functions

1.1.3. Understanding time and space

1.1.4. Are callbacks out of the picture?

1.1.5. Event Emitters

1.2. Better callbacks with promises

1.3. The need for a different paradigm

1.4. The Reactive Extensions for JavaScript (RxJS)

1.4.1. Thinking in streams: data flows & propagation

====Introducing the RxJS project ==== Everything is a stream ==== Abstracting the notion of time from your programs ==== Components of an Rx Stream === Reactive and other programming paradigms === Summary

2. Reacting with RxJS

2.1. Functional programming as the pillar of reactive programming

2.1.1. Functional programming

2.1.2. The Iterator pattern

2.2. Stream's data-driven approach

2.3. Wrapping data sources with Rx.Observable

2.3.1. Identifying different sources of data

2.3.2. Creating RxJS Observables

2.3.3. When and where to use RxJS

2.3.4. To push or not to push

2.4. Consuming data with observers

2.4.1. The Observer API

2.4.2. Creating bare observables

2.4.3. Observable modules

2.5. Summary

3. Core operators

3.1. Evaluating and cancelling streams

3.1.1. Downside of eager allocation

3.1.2. Lazy allocation and subscribing to observables

3.1.3. Disposing of subscriptions: explicit cancellation

3.1.4. Cancellation mismatch between RxJS and other APIs

3.2.1. Introducing the core operators

3.3. Sequencing operator pipelines with aggregates

3.3.1. Self-contained pipelines and referential transparency

3.3.2. Performance advantages of sequencing with RxJS

3.4. Summary

4. It's About Time You Used RxJS

4.1. Why worry about time?

4.2. Understanding asynchronous timing with JavaScript

4.2.1. Implicit timing

4.2.2. Explicit Timing

4.2.3. The JavaScript timing interfaces

4.3. Back to the future with RxJS

4.3.1. Propagation

4.3.2. Sequential time

4.4. Handling user input

4.4.1. Debouncing

4.4.2. Throttling

4.5. Buffering in RxJS

4.6. Summary

Part 2

5. Applied Reactive Streams

5.1. One for all, and all for one!

5.1.1. Interleave events by merging streams

5.1.2. Preserve order of events by concatenating streams

5.1.3. Switch to the latest observable data

5.2. Unwinding nested observables: the case of mergeMap

5.3. Mastering asynchronous streams

5.4. Drag and drop with concatMap

5.5. Summary

6. Coordinating business processes

6.1. Hooking into the observable lifecycle

6.1.1. Web hooks and the observer pattern

6.1.2. Hooked on observables

6.2. Joining parallel streams with combineLatest and forkJoin

6.2.1. Limitations of using promises

6.2.2. Combining parallel streams

6.2.3. More coordination with fork-join

6.3. Building a reactive database

6.3.1. Populating a database reactively

6.3.2. Writing bulk data

6.3.4. Reactive databases

6.4. Summary

7. Error Handling with RxJS

7.1. Common error-handling techniques

7.1.1. Error-handling with try/catch

7.1.2. Delegating errors to callbacks

7.1.3. Errors and promises

7.2. Incompatibilities between imperative error-handling techniques and functional and reactive code bases

7.3. Understanding the functional error-handling approach

7.4. The RxJS way of dealing with failure

7.4.1. Errors propagated downstream to observers

7.4.2. Catching and reacting to errors

7.4.3. Retrying failed streams for a fixed number of times

7.4.4. Reacting to failed retries

7.5. Summary

Part 3

8. Heating up observables

8.1. Introducing hot and cold observables

8.1.1. Cold Observables

8.1.2. Hot observables

8.2. A new type of data source: WebSockets

8.2.1. A brief look at WebSockets

8.2.2. A simple WebSocket server in Node.js

8.2.3. WebSocket client

8.3. The impact of side effects on a re-subscribe or a replay

8.3.1. Replay vs. re-subscribe

8.3.2. Replaying the logic of a stream

8.3.3. Re-subscribing to a stream

8.4. Changing the temperature of an Observable

8.4.1. Producers as thermometers

8.4.2. Making a hot observable cold

8.4.3. Making a cold observable hot

8.4.4. Creating hot-by-operator streams

8.5. Connecting one observable to many observers

8.5.1. Publishing the stream data

8.5.2. Publish with replay

8.5.3. Publish last

8.6. Summary

9. Toward testable, reactive programs

9.1. Testing is inherently built into functional programs

9.2. Testing asynchronous code and promises

9.2.1. Testing AJAX requests

9.2.2. Working with promises

9.3. Testing reactive streams

9.4. Making streams testable

9.5. Scheduling values in RxJS

9.6. Augmenting virtual reality

9.6.1. Playing with marbles

9.6.2. Fake it til' you make it

9.6.3. Refactoring our search stream for testability

9.7. Summary

10. RxJS in the Wild

10.1. Building a basic banking application

10.2. Introduction to React and Redux

10.2.1. Rendering UI components with React

10.2.2. State management with Redux

10.3. Redux-ing application state

10.3.1. Actions and Reducers

10.3.2. Redux Store

10.4. Building a hot RxJS and Redux store adapter

10.5. Asynchronous middleware with RxJS Subject

10.5.1. RxJS Subjects

10.5.2. Building an epic, reactive middleware

10.6. Bringing it all home

10.7. Parting words

10.8. Summary


Appendix A: Libraries used in this book

A.1. Installing RxJS

A.2. Installing Ramda.js

A.3. Installing PouchDB

A.4. Installing Moment.js

A.5. Installing Google Client APIs

A.6. Using the Bitly Web API

A.7. Installing Mocha

A.8. Installing Chai.js

A.9. Installing React.js

A.10. Installing React-Bootstrap

A.11. Installing Redux.js

Appendix B: Choosing an operator

What's inside

  • Creating readable, easy-to-understand event processing pipelines
  • Using a unified programming model to tackle asynchronous data
  • Composing and sequencing RxJS operators
  • Decoupling error handling from business logic
  • Scheduling for event propagation and synchronization
  • Transform bulky, untestable code into modular, testable expressions
  • Embedding Rx into other JavaScript frameworks

About the reader

This book is for readers who are comfortable writing and building applications in JavaScript.

About the authors

Paul P. Daniels is a professional Software Engineer with a B.S.E in Computer Science and over 5 years of experience in software engineering, developing applications in .Net, Java, and JavaScript. A regular user of RxJS, he is active as a member and a contributor in the RxJS community. Luis Atencio is a Staff Software Engineer for Citrix Systems. He has a B.S. and an M.S. in Computer Science and works full-time developing and architecting web applications using Java, PHP, and JavaScript platforms. Luis is also the author of Functional Programming in JavaScript.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks