Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the name "Behavior" in BehaviorSubject in RX?

I'm curious, why do you think they used the name "Behavior" for the BehaviorSuject object in Ractive Extensions?

note: a behavior subject returns the last value (or the init vaue) as the first value to any subscriber.

like image 448
Nestor Avatar asked Oct 12 '12 17:10

Nestor


People also ask

What is Behaviour in angular?

Behavior subject is the most common subject in angular. The Behavior subject represents the current value and it is imported from the Rxjs library. It is similar to the subject but the difference is that we can set the initial value in the behavior subject.

What is behavior subject in RxJS?

BehaviorSubject is a variant of a Subject which has a notion of the current value that it stores and emits to all new subscriptions. This current value is either the item most recently emitted by the source observable or a seed/default value if none has yet been emitted.

What is difference between subject and behavior subject?

A BehaviorSubject holds one value (so we actually need to initialize a default value). When it is subscribed it emits that value immediately. A Subject on the other hand, does not hold a value.

Why do we use BehaviorSubject in angular?

As we know multiple components share the common data and always need updated shared data. In such scenarios most of the time BehaviorSubject is used which acts as a single store to hold updated shared data. BehaviorSubject is both observer and type of observable.


1 Answers

In the world of functional reactive programming, a behavior is a value that changes over time. This is exactly what a BehaviorSubject represents: when you subscribe you get the current value, and then you can continue to observe the changes. See http://en.wikipedia.org/wiki/Functional_reactive_programming.

like image 160
Bart De Smet Avatar answered Oct 06 '22 02:10

Bart De Smet