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.
In your example, couldn't you just write b
as a function?
var b = function(a) {
return 10 * a;
}
Problem with the typo solved.
Hi Daniel. We could, but that has its problems too, watch this presentation to see why: https://www.youtube.com/watch?v=BfZpr0USIi4
Yeah, I was thinking the same thing. But I think that was a very contrived example Andre used to illustrate the concept
How can I change the values dynamically? What if I don't know regarding the 4 in the initial state?
var streamA = Rx.Observable.of(3, 4);
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.
Hey Andre, hope you have made an "observable" of this thread and are still "subscribed" to new comments :oP
Regards your answer to Kostaintyn above, are you basically saying that the values 'can' change over time but what needs to be specified at declaration only once is the 'type' of construct that is creating the change so that RxJS knows how to treat it?
e.g. Obviously we cant know when a user will click a mouse, so we cant hard code all possible clicks and their values for clientX at declaration... but we can specify where the values should come from (fromEvent). In this way we are fulfilling the comment you wrote in this video and we have "specified the dynamic behaviour of a value at declaration"...its an event emitter! Thats its behaviour!
I cant speak for everyone else... but I know my confusion came from the thought "great, I will learn RxJS and finally turn an array that could change over time into a dynamic stream of data that is subscribed to by various parts of my app, when it changes over time all parts of my app subscribed will know". Since arrays aren't event driven they don't contain any native method of emitting an event to say they have been updated, hence the RxJS "Subject" has to be used to artificially convert them into an event emitter - correct me if I am wrong??
I don't know if you maybe had the same problem when you tried to learn RxJS
There is mental error in code.
streamB.subscribe(b => console.log(b)) || displayInPreview(b);
The displayInPreview never runs and does not makes sense. Probably that was made after intent to concise the code by using ES2015 arrow functions.
This no longer works as of version 7
streamB = streamA.map()