gothinkster/angular-realworld-example-app

Why you use new ReplaySubject<boolean>(1)?

Closed this issue · 1 comments

What are the benefits of using 1" vs "true" for the initial value of the BehaviorSubject instance in this line?

private isAuthenticatedSubject = new ReplaySubject<boolean>(1);

What puzzles me more is that the tutorial uses value "false" instead for this same line here:

https://thinkster.io/tutorials/building-real-world-angular-2-apps/intercept-and-manipulate-http-requests

Ok, it turns out that "1" is not the initial value of the observable; because it is a ReplaySubject, not a BehaviorSubject. So the "1" says store and replay one value from the stream (the last one). There is no initial value with ReplaySubject.