O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using RxJS to manage user input

Now we must implement the observables to listen to user input; they are going to be used to send messages to the server.

Let's implement the events.js file inside the client folder.

The first thing to do is to use the RxJS module:

var Rx = require('rx'); 

We want to send the user messages every time the user hits the Send message button or when the user hits enter in the message box.

For this reason, we need two observables, the first to trigger when the user clicks on the Send message button:

var sendPressedObservable = Rx.Observable     .fromEvent(document.getElementById('send_message'),'click'); 

This observable is simple and just propagates the event whenever the user clicks on the button.

The second observable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required