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

RxJS Subjects

Subjects could be both an Observable and an Observer. They can be seen as a pushable Observable; they let you add more data to be propagated through them.

Subjects expose three important methods: onNext(), onError(), and onCompleted(). These methods can be used to send events through the observable sequence. You can see their usage in the following example:

var subject = new Rx.Subject(); subject.subscribe(     (message)=> console.log(message),     (err)=>console.log('An error happened: '+err.message),     ()=>console.log('END') ); subject.onNext('Hello World!!!'); subject.onCompleted(); 

In this example, we created a new subject and subscribed to it, using the subscribe() method. Then, we pushed data on this subject using the onNext() ...

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