- Remember the second subscribe
started with the number two
because that was the latest value
when we subscribed?
What if you want to get all the values
that have passed through a subject
since the beginning?
No problem.
You just need a replay subject.
The replay subject will save all the values
and give them to each subscriber
even after the replay subject has been completed.
Let's take a look.
We'll go ahead and change our behavior subject
to a replay subject.
And again, we'll hold down option
so we can select multiple lines
and change it all at once.
Now remember behavior subject
required an initial value.
Replay subject doesn't.
You can leave it here if you want to
but it will be ignored,
so we're going to go ahead and remove that.
Now let's see what it looks like on the console log.
Remember we're not changing
any of the other code.
We have the first subscribe,
then the one, then the two
then the second subscribe
then the three.
Let's see what that looks like.
Okay. Now both subscribes got all three values.
They're still going in the order
that they were called.
So we have the first subscriber
with the one and two.
Then the second subscriber
with the one and two.
Then later they both get the value three.
There are more subjects
so if there is something specific
you're trying to do and it's not here
check out that Reactive X website
and you'll probably find one
that does exactly what you need.
But we have a lot more to cover
so let's keep moving.