Reactive programming is revolutionary. It makes asynchronous programming cleaner, intuitive, and robust. Discover how to use the RxJS library to write programs in a simpler way, unifying asynchronous mechanisms such as callbacks and promises into a single, powerful construct. Learn to think about your programs as streams of data that you can transform by expressing what should happen, instead of having to painstakingly program how it should happen. You’ll be able to handle real-world concurrency and write complex flows of events in your applications with ease.
Reactive Programming with RxJS: Untangle Your Asynchronous JavaScript Code
by Sergi Mansilla
About This Book
Create highly concurrent applications while writing simpler code using the Reactive Extensions for JavaScript (RxJS), a set of libraries for composing events in your programs. Programming real-world applications in JavaScript involves lots of asynchronous events—so many that you might end up spending more time coordinating asynchronous code than writing the actual functionality of your program. This book introduces concepts and tools from reactive programming that will help you write simpler and more robust asynchronous programs.
You’ll find out about Observable sequences, a unifying data type to write highly concurrent code, and Schedulers, the RxJS data type you use to change the concept of time in your applications to make asynchronous code tests sane again. Along the way you’ll see real-world examples for the browser and Node.js, including a real-time earthquake visualization in 20 lines of code and a frantic shoot-’em-up space videogame. You’ll also learn how to use Cycle.js – a modern, fully reactive web framework – to make a whole new breed of web applications.
By the end of the book, you’ll know how to apply reactive programming to solve complex problems, build efficient programs with reactive user interfaces, and write your code more declaratively.
What You Need
A modern web browser, Node.JS installed in your computer, and the RxJS JavaScript library.
Resources
Contents & Extracts
This book is currently in beta, so the contents and extracts will change as the book is developed.
- Preface
- New World, Old Methods
- What Is Reactive Programming?
- What is RxJS?
- Who This Book Is For
- What’s In This Book
- Running the Code Examples
- Resources
- Download Sample Code
- The Reactive Way excerpt
- What’s Reactive?
- Of Observers and Iterators
- The Rx Pattern and the Observable
- Creating Observables
- Wrapping Up
- Deep in the Sequence
- Visualizing Observables
- Basic Sequence Operators
- Handling Errors
- Making a Real-Time Earthquake Visualizer
- Wrapping Up
- Building Concurrent Programs
- Purity and the Observable Pipeline
- RxJS’s Subject Class excerpt
- Spaceship Reactive!
- Wrapping Up
- Building a Complete Web Application
- Building a Real-Time Earthquake Dashboard
- Adding a List of Earthquakes
- Getting Real-Time Updates from Twitter
- Ideas for Improvements
- Wrapping Up
- Bending Time with Schedulers excerpt
- Using Schedulers
- Scheduling for Visual Updates
- Creating Your Own Schedulers
- Testing with Schedulers
- Wrapping Up
- Reactive Web Applications with Cycle.js
- Cycle.js
- Installing Cycle.js
- Our First Application
- Model View Intent
- Creating Reusable Widgets
- Wrapping Up
Brought to You By
Sergi Mansilla is a professional developer with more than 15 years of experience who believes that software can change the world for the better. He’s currently working on Firefox OS, a new mobile OS based on the web. Sergi speaks at conferences all around the world, and lives in Amsterdam with his lovely wife.