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

DataSource

As we have no interest in keep the history of messages nor in implementing a login for our server (the users are going to just type a name and this name will be used), we can use a simple observable to implement our DataSource; this DataSource will contain only the messages sent from user to user and broadcast messages.

Our DataSource must have two methods: the first to push new messages, and the second to listen to incoming messages. We can use a RxJS Subject to implement this behavior as it lets us push data to our observable. We could also user an observable using the create() method to create it from an arbitrary source, but the code with a Subject will be a lot easier to read and to understand:

let Rx = require('rx'); let ...

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