From the course: Learning RxJS

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Replaying changes with replay subjects

Replaying changes with replay subjects

From the course: Learning RxJS

Replaying changes with replay subjects

- [Instructor] After using subjects, we were able to convert temperature from Fahrenheit to Celsius. It did a really good job converting the values, but what if we want to convert all the previous values as well? If we wanted to do this without any array or any other data structure, we'd be able to use a special type of observable called a ReplaySubject. ReplaySubjects remember every value that's been passed to it and we'll pass all of them to new subscriptions in the same order. If we have Fahrenheit values of 61, 63 and 67 degrees Fahrenheit, pass into a ReplaySubject, a current subscription will receive those values. Newer subscriptions that join later will also be immediately passed the same values. With that, we can convert the temperatures to Celsius. To review, BehaviorSubjects have an initial value and can be accessed anytime without subscribing to the observable. Subjects don't have an initial value and only…

Contents