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

Creating an observable from an arbitrary source

In the previous chapter, we discussed how to implement an observable from an arbitrary source in bacon.js, using the fromBinder event. On RxJS, we can also create an observable from any source that we want using the create() method. There is also an alias for this method, called createWithDisposable.

The create() method has the following signature:

Rx.Observable.create(sourceFunction); 

This method accepts only one parameter and it is mandatory:

  • sourceFunction: This is a function that receives an object capable of pushing data into an observable

We can create an observable with the create() method using the following code:

Rx.Observable.create(function(source){     source.onNext(0);  source.onNext(1); ...

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