Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Reactive JavaScript
Mastering Reactive JavaScript

Mastering Reactive JavaScript: Building asynchronous and high performing web apps with RxJS

Arrow left icon
Profile Icon Erich de Souza Oliveira
Arrow right icon
zł39.99 zł141.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (4 Ratings)
eBook May 2017 310 pages 1st Edition
eBook
zł39.99 zł141.99
Paperback
zł177.99
Subscription
Free Trial
Arrow left icon
Profile Icon Erich de Souza Oliveira
Arrow right icon
zł39.99 zł141.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (4 Ratings)
eBook May 2017 310 pages 1st Edition
eBook
zł39.99 zł141.99
Paperback
zł177.99
Subscription
Free Trial
eBook
zł39.99 zł141.99
Paperback
zł177.99
Subscription
Free Trial

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Reactive JavaScript

Reacting for the First Time

In the previous chapter, you started understanding the motivations behind using functional reactive programming in your systems; you also saw how a program using this paradigm fared against a program without it. You learned how reactive programming can improve code readability and testability by decoupling your event sources from the action you take when the action occurs.

We started with some basic examples using bacon.js as the reactive programming library for JavaScript. In the examples, we began with creating our first EventStream from an interval. Then we started using some operators (map() and take()). Finally, we subscribed to this event source to take actions in the case of an event occurrence. This was just a kind introduction to functional reactive programming.

When reading most of the functional reactive programming libraries (for any language), you will see a lot of diagrams...

The bacon.js observables

In functional reactive programming, an observable is an object where you can listen for events. This way, you can, for instance, create an observable for a button and then listen and act when a click happens.

The bacon.js gives you two flavors of an observable: the first one is EventStream and the other is Property. We will see the difference between the two objects later. To listen to events in an observable (or subscribe to an observable), you can use the onValue()method with a callback. So if you want to log every event in an EventStream, you can use the following code:

myEventStream.onValue(function(event){ 
console.log(event);
});
We will see how to create an EventStream in more detail later.

As we saw in the example in the last chapter, we can transform our observable using bacon.js operators. These operators let us filter, combine, map, buffer, and do a lot of other interesting...

Reacting to changes

As discussed earlier, an observable is an object where you can listen to events. The act of listening to events in this object is called subscription. Here, we will see the different ways in which we can subscribe to an observable and also how we can stop listening to events in this observable (unsubscribe).

Subscribing

We call subscribing to an observable an act of adding a function to be called when an event happens. Using bacon.js, we can be notified when a value is emitted (the onValue(), log(), and assign() methods), when an error has occurred (the onError() method), or when our observable is closed (at the end).

Subscribing using the...

Reading how an operator works

Throughout this book, you will see a lot of diagrams explaining how an operator works. These diagrams are a graphical representation of observables and operations in those observables. Usually, the diagrams consist of three parts. On the top they shows a line with balls representing the initial state of an observable. The line itself represents an observable. The circles are events that happened in this observable and they are pushed from left to right; therefore, the leftmost ball is the first event, the second one is the second, and so on. This is illustrated in the following diagram:

So, the preceding line represents an observable with three emitted events. The string at the center of each circle is the value emitted by that event. The short vertical line on the right-hand side of the diagram represents the end of this observable. This diagram is a graphical representation...

Transforming events using bacon.js

One important thing when learning functional reactive programming is how you can transform the events emitted by an observable. This way, you can use successive function calls to create new objects from the original input. This also improves the reuse of your code; every transformation of an observable creates a new observable, and each observable can have several listeners subscribed to it.

Before applying any transformations to our observables, let's implement an observable to generate and print the current date. To do this, let's use the Bacon.interval() method. So, the following code will emit an empty object every second:

var eventSource = Bacon 
.interval(1000);
Remember, Bacon.interval() emits an empty object every x milliseconds, where x is the argument passed to the function–in our example, every 1000 milliseconds, which is the same as every...

Summary

In this chapter, you learned the basics of functional reactive programming using the bacon.js library. We wanted to give you the taste of functional reactive programming and also get your hands dirty with a lot of different examples.

You learned about observables and the different types of observables that bacon.js has implemented. You also learned about some of the built-in methods that help you create observables in bacon.js and also how you can create your own observable using the fromBinder() method.

Apart from this, you also learned how to subscribe and unsubscribe from an observable, how to use operators to transform an observable, and the importance of reuse in this context.

In the next chapter, we will start using RxJS as it gives us more tools for functional reactive programming. We will see how it compares with bacon.js and understand the basics of this new tool.

...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Handle an infinite stream of incoming data using RxJs without going crazy
  • Explore important RxJs operators that can help you improve your code readability
  • Get acquainted with the different techniques and operators used to handle data traffic, which occurs when you receive data faster than you can process

Description

If you’re struggling to handle a large amount of data and don’t know how to improve your code readability, then reactive programming is the right solution for you. It lets you describe how your code behaves when changes happen and makes it easier to deal with real-time data. This book will teach you what reactive programming is, and how you can use it to write better applications. The book starts with the basics of reactive programming, what Reactive Extensions is, and how can you use it in JavaScript along with some reactive code using Bacon. Next, you’ll discover what an Observable and an Observer are and when to use them.You'll also find out how you can query data through operators, and how to use schedulers to react to changes. Moving on, you’ll explore the RxJs API, be introduced to the problem of data traffic (backpressure), and see how you can mitigate it. You’ll also learn about other important operators that can help improve your code readability, and you’ll see how to use transducers to compose operators. At the end of the book, you’ll get hands-on experience of using RxJs, and will create a real-time web chat using RxJs on the client and server, providing you with the complete package to master RxJs.

Who is this book for?

If you're a web developer with some basic JavaScript programming knowledge who wants to implement the reactive programming paradigm with JavaScript, then this book is for you.

What you will learn

  • Get to know the basics of functional reactive programming using RxJs
  • Process a continuous flow of data with linear memory consumption
  • Filter, group, and react to changes in your system
  • Discover how to deal with data traffic
  • Compose operators to create new operators and use them in multiple observables to avoid code repetition
  • Explore transducers and see how they can improve your code readability
  • Detect and recover from errors in observables using Retry and Catch operators
  • Create your own reactive application: a real-time webchat

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 26, 2017
Length: 310 pages
Edition : 1st
Language : English
ISBN-13 : 9781786463463
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 26, 2017
Length: 310 pages
Edition : 1st
Language : English
ISBN-13 : 9781786463463
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 zł20 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 zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 553.97
React Design Patterns and Best Practices
zł197.99
Mastering Reactive JavaScript
zł177.99
Comprehensive Ruby Programming
zł177.99
Total 553.97 Stars icon
Banner background image

Table of Contents

11 Chapters
What Does Being Reactive Mean? Chevron down icon Chevron up icon
Reacting for the First Time Chevron down icon Chevron up icon
A World Full of Changes - Reactive Extensions to the Rescue Chevron down icon Chevron up icon
Transforming Data - Map, Filter, and Reduce Chevron down icon Chevron up icon
The World Changes Too Fast - Operators to Deal with Backpressure Chevron down icon Chevron up icon
Too Many Sources - Combining Observables Chevron down icon Chevron up icon
Something is Wrong - Testing and Dealing with Errors Chevron down icon Chevron up icon
More about Operators Chevron down icon Chevron up icon
Composition Chevron down icon Chevron up icon
A Real-Time Server Chevron down icon Chevron up icon
A Real-Time Client Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(4 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 50%
1 star 0%
Yuri Oliveira Aug 21, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As someone getting into Reactive Programming for the first time, the book is well paced and easy to read, with concrete examples, making it very easy to understand.
Amazon Verified review Amazon
Chetan Munegowda May 05, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I highly recommend this book.
Amazon Verified review Amazon
Martin Longbow Dec 03, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Ill update when done reading, BUT WHY are you using rxjs 4.*, when rxjs 5 was available at the time of publish. You should have updated code examples. Its like writing a book on Angular 1.*, when 2.0 is already out. Aaarg.Update 1: I adjusted my rating down to 2 stars. Why? I'm running across a lot of rxjs 4 operators that are not in rxjs 5. So, I'm wondering should I skip this section, or not waste my time with the pages I am reading. I'm debating on whether to return this item or not.
Amazon Verified review Amazon
Johannes Löwe Oct 28, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
This is a book for people just getting into RxJS and does not at all lead to mastering it. Considering the price, the amount of actual information in the book was disappointing.
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.