Reactive Programming with RxJS Untangle Your Asynchronous JavaScript Code 1st Edition Sergi Mansilla download
Reactive Programming with RxJS Untangle Your Asynchronous JavaScript Code 1st Edition Sergi Mansilla download
https://ebookfinal.com/download/reactive-programming-with-rxjs-
untangle-your-asynchronous-javascript-code-1st-edition-sergi-
mansilla/
https://ebookfinal.com/download/html5-programming-with-javascript-for-
dummies-mueller/
https://ebookfinal.com/download/asynchronous-android-programming-2nd-
edition-helder-vasconcelos/
https://ebookfinal.com/download/node-up-and-running-scalable-server-
side-code-with-javascript-1st-edition-tom-hughes-croucher/
https://ebookfinal.com/download/programming-reactive-extensions-and-
linq-1st-edition-jesse-liberty/
Learn Unity3D Programming with UnityScript Unity s
JavaScript for Beginners 1st Edition Janine Suvak
https://ebookfinal.com/download/learn-unity3d-programming-with-
unityscript-unity-s-javascript-for-beginners-1st-edition-janine-suvak/
https://ebookfinal.com/download/modern-c-programming-with-test-driven-
development-code-better-sleep-better-1st-edition-jeff-langr/
https://ebookfinal.com/download/handbook-of-asynchronous-machines-
with-variable-speed-1st-edition-hubert-razik/
https://ebookfinal.com/download/learn-game-programming-with-ruby-
bring-your-ideas-to-life-with-gosu-mark-sobkowicz/
https://ebookfinal.com/download/getting-started-with-advanced-c-
upgrade-your-programming-skills-1st-edition-vaskaran-sarcar/
Reactive Programming with RxJS Untangle Your
Asynchronous JavaScript Code 1st Edition Sergi Mansilla
Digital Instant Download
Author(s): Sergi Mansilla
ISBN(s): 9781680501292, 1680501291
Edition: 1
File Details: PDF, 3.65 MB
Year: 2015
Language: english
Early praise for Reactive Programming with RxJS
This book is as hot as reactive programming itself! With great writing, clear expla-
nations, and practical examples, this is a fantastic resource for learning RxJS.
➤ Fred Daoud
Software-development contractor
Be proactive and learn reactive programming with this book before it’s too late.
Rx.Observable.fromBook(book).subscribe(function(value) {...do amazing stuff...});
➤ Javier Collado Cabeza
Senior software developer, NowSecure, Inc.
A very readable book with great content. This book is eminently useful and provides
a clear roadmap for learning reactive programming with RxJS with practical ex-
amples.
➤ Ramaninder Singh Jhajj
Software engineer, Area Services & Development, Know-Center, Austria
We've left this page blank to
make the page numbers the
same in the electronic and
paper books.
Sergi Mansilla
Acknowledgments . . . . . . . . . . . ix
Preface . . . . . . . . . . . . . . xi
Index . . . . . . . . . . . . . . 119
Acknowledgments
I have so many people to thank. There are those who have helped shape the
book and those who have helped shape me as a person. I couldn’t have done
this without any of them. I would particularly like to thank the following:
The exceptional people who came up with the Reactive Extensions library in
the first place, and the ones who expanded and evangelized it. This book
would obviously not exist without you: Erik Meijer, Matt Podwysocki, Bart
De Smet, Wes Dyer, Jafar Husain, André Staltz, and many more I am probably
forgetting.
The folks at The Pragmatic Bookshelf. It has been a pleasure to work with
you. Special thanks to Susannah Pfalzer, who has believed in the book since
it was nothing but an idea. I was also extremely lucky to get Rebecca Gulick
as my editor: You have been professional, patient, attentive to my questions,
and a joy to work with. I’ve been a fan of Pragmatic’s books for a long time,
and it has been a privilege to write a PragProg book myself. And, yes, both
publishers, Dave Thomas and Andy Hunt, do read and review every book!
The brilliant technical reviewers. David Bock, Javier Collado Cabeza, Fred
Daoud, Irakli Gozalishvili, Zef Hemel, Ramaninder Singh Jhajj, Aaron Kalair,
Daniel Lamb, Brian Schau, and Stephen Wolff, as well as Pragmatic publishers
Dave and Andy: This book is infinitely better thanks to all of you. You each
selflessly put time and energy into reviewing this book, detecting complicated
errors and saving me from more than one embarrassing mistake. Any errors
remaining in the book are my own fault.
To my friends. The ones who are always there, no matter the time and the
distance; you know who you are. Thanks for the laughs, the support, the
love.
My parents, Narcís Mansilla and Joana Molins. You are my guides and role
models. You never ceased to believe in me and always encouraged me to take
on bigger challenges. You bought me my first computer at a time when you
struggled to pay the bills. That started it all, and I owe you everything.
My son, Adrià. You were born while I was writing this book, and you have
changed the meaning of life for me. You’ve already taught me so much in
such little time, and I can’t wait to see what’s next.
Finally, Jen, the love of my life. You have had infinite patience and supported
me while I wrote a book in one of the busiest periods of our life so far. You
are an inspiration to me and you make me a better human being in every
way. You are my star.
Sergi Mansilla
Barcelona, December 2015
Most software today deals with data that’s available only over time: websites
load remote resources and respond to complex user interactions, servers are
distributed across multiple physical locations, and people have mobile devices
that they expect to work at all times, whether on high-speed Wi-Fi or spotty
cellular networks. Any serious application involves many moving asynchronous
parts that need to be efficiently coordinated, and that’s very hard with today’s
programming techniques. On top of that, we have what’s always been there:
servers crashing, slow networks, and software bugs we have to deal with.
And yet we’re still using good ol‘ imperative-style programming to deal with
problems that are essentially asynchronous. This is very hard.
1. http://venturebeat.com/2012/01/24/why-walmart-is-using-node-js/, http://techblog.netflix.com/2014/06/scale-
and-performance-of-large.html
Callback Functions
A callback is a function (A) passed as a parameter to another function (B) that
performs an asynchronous operation. When (B) is done, it calls back (A) with
the results of the operation. Callbacks are used to manage asynchronous
flows such as network I/O, database access, or user input.
intro/callback_example.js
function B(callback) {
// Do operation that takes some time
callback('Done!');
}
function A(message) {
console.log(message);
}
Callbacks are easy to grasp and have become the default way of handling
asynchronous data flows in JavaScript. But this simplicity comes at a price.
Callbacks have the following drawbacks:
• Callback hell. It’s easy to end up with lots of nested callbacks when han-
dling highly asynchronous code. When that happens, code stops being
linear and becomes hard to reason about. Whole applications end up
passed around in callbacks, and they become difficult to maintain and
debug.
• Callbacks can run more than once. There’s no guarantee the same callback
will be called only once. Multiple invocations can be hard to detect and
can result in errors and general mayhem in your application.
Promises
Promises came to save us from callbacks. A promise represents the result of
an asynchronous operation. In promise-based code, calling an asynchronous
function immediately returns a “promise” that will eventually be either resolved
with the result of the operation or rejected with an error. In the meantime,
the pending promise can be used as a placeholder for the final value.
Event Emitters
When we emit an event, event listeners that are subscribed to it will fire.
Using events is a great way to decouple functionality, and in JavaScript, event
programming is common and generally a good practice.
But, you guessed it, event listeners come with their own set of problems, too:
• Events force side effects. Event listener functions always ignore their
return values, which forces the listener to have side effects if it wants to
have any impact in the world.
• Events are not first-class values. For example, a series of click events can’t
be passed as a parameter or manipulated as the sequence it actually is.
We’re limited to handling each event individually, and only after the event
happens.
Since these mechanisms are what we’ve always used to manage concurrency,
it might be hard to think of a better way. But in this book I’ll show you one:
reactive programming and RxJS try to solve all these problems with some
new concepts and mechanisms to make asynchronous programming a breeze
—and much more fun.
What Is RxJS?
RxJS is a JavaScript implementation of the Reactive Extensions, or Rx.2 Rx
is a reactive programming model originally created at Microsoft that allows
developers to easily compose asynchronous streams of data. It provides a
common interface to combine and transform data from wildly different sources,
such as filesystem operations, user interaction, and social-network updates.
2. https://rx.codeplex.com/
We’ll be developing mostly for the browser, but we’ll see some examples in
Node.js, too. We’ll get deep into the subject early on, and we’ll build applica-
tions along the way to keep it real. Here are the chapters:
Unless you have used RxJS before, start with Chapter 1, The Reactive Way,
on page 1. In this chapter we introduce Observables, the main data type of
RxJS, which we’ll use extensively throughout the book.
We get into some more advanced concepts of RxJS with Chapter 5, Bending
Time with Schedulers, on page 89, where we talk about the useful concept
RxJS provides to handle concurrency at a more fine-grained level: Schedulers.
With the knowledge of Schedulers under our hats, we explore how they help
us with testing. We’ll see how to simulate time in our tests to accurately test
asynchronous programs.
Keep in mind that it is a relatively big file and you may want to consider a
smaller file, such as rx.js or rx.lite.js, for your projects if you’re not using all the
functionality in RxJS.
After that, you can import the RxJS library in your JavaScript files:
var Rx = require('rx');
Rx.Observable.just('Hello World!').subscribe(function(value) {
console.log(value);
});
And you can run it by simply invoking node and the name of the file:
$ node test.js
Hello World!
3. https://github.com/Reactive-Extensions/RxJS/tree/master/dist
RxJS Version
All the examples are made for RxJS 4.x. You can download the latest version
in the RxJS online repository.4
Resources
RxJS is gaining adoption very quickly, and there are more and more resources
about it every day. At times it might be hard to find resources about it online,
though. These are my favorite ones:
4. https://github.com/Reactive-Extensions/RxJS/releases/latest
5. https://github.com/Reactive-Extensions/RxJS
6. http://reactivex.io
7. http://rxmarbles.com/
8. http://pragprog.com/titles/smreactjs
What’s Reactive?
Let’s start by looking at a little reactive RxJS program. This program needs
to retrieve data from different sources with the click of a button, and it has
the following requirements:
• It must unify data from two different locations that use different JSON
structures.
• To avoid requesting data too many times, the user should not be able to
click the button more than once per second.
FIN
Arcis-sur-Aube. — Typ. Frémont
NOTE DU TRANSCRIPTEUR
La publication dans la Revue Blanche en 1899-1900
comprenait trois parties séparées en chapitres. L'édition en
volume a retiré la séparation en parties, et renuméroté les
chapitres de I à XXVI, à l'exception du chapitre V de la
troisième partie, oublié lors de la renumérotation.
On a retiré la mention "première partie" qui restait en
tête du premier chapitre, et repris la numérotation des
chapitres à partir de ce chapitre V de la troisième partie,
qui devient le chapitre XXI.
*** END OF THE PROJECT GUTENBERG EBOOK LE VŒU D'ÊTRE
CHASTE: ROMAN ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com