The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Reactive Programming - Why choose RxJS?

Reactive Programming - Why choose RxJS?

4:05
This lesson helps you think in Reactive programming by explaining why it is a beneficial paradigm for programming. See how reactive programming helps you understand the dynamic behavior of a value evolving over time.
Watch this lesson now
Avatar
egghead.io

This lesson helps you think in Reactive programming by explaining why it is a beneficial paradigm for programming. See how reactive programming helps you understand the dynamic behavior of a value evolving over time.

Avatar
dave

I'm confused, in Bacon.js I can push new values into a stream and the listeners will be updated , in your video you seem to be saying a stream shouldn't be updated you have to set all values upfront . I cannot see how that is very useful ? Can you elaborate please.

In reply to egghead.io
Avatar
Andre

Hi Dave. Also in RxJS you can push new values into a stream, if that stream is a Subject. However, that is not anymore reactive programming. What I explained in this lesson was, in order to stay in the realm of reactive programming and reap its benefits, we shouldn't update/push a stream. Everything that can possibly change the stream should be defined at the time of declaration, regardless if that change is instantaneous at the time of declaration or if the change will come later in the future through some other Observable.

In reply to dave
Avatar
Daniel

In your example, couldn't you just write b as a function?

var b = function(a) {
  return 10 * a;
}

Problem with the typo solved.

Avatar
Andre

Hi Daniel. We could, but that has its problems too, watch this presentation to see why: https://www.youtube.com/watch?v=BfZpr0USIi4

In reply to Daniel
Avatar
Paul

Yeah, I was thinking the same thing. But I think that was a very contrived example Andre used to illustrate the concept

In reply to Daniel
Avatar
Kostiantyn

How can I change the values dynamically? What if I don't know regarding the 4 in the initial state?

streamA = Rx.Observable.of(3, 4);```
Avatar
Andre

Kostiantyn, all the dynamic updates should be specified in the declaration of the observable. That's the reactive approach. You don't need to know beforehand exactly what values, but you need to know from where will these dynamic values come from. If you want to change the values according to clicks, then you declare the observable with a dependency on the click observable, for example.

In reply to Kostiantyn
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?