I'm curious. What's the intent behind using an empty pipe() call in the definition of the isMaximized$ property? I don't think I've often seen code where a call is made to pipe() that doesn't include operators within it. Does it help in the subscription teardown or something similar?
privateisMaximizedSubject=newBehaviorSubject(false);isMaximized$=this.isMaximizedSubject.pipe();// Another wayisMaximized$=this.isMaximizedSubject.asObservable();
Both ways convert the subject into an observable. So you convert subjects to observables and expose only the observables to make sure consumers cannot call next() and emit values.
Update: I have changed it to asObservable as I don't want to create this impression. Using asObservable is probably the better approach.
I am a full stack web applications development lead, having more than 10 years of extensive experience in all phases of small-scale to enterprise-scale projects.
I'm curious. What's the intent behind using an empty pipe() call in the definition of the isMaximized$ property? I don't think I've often seen code where a call is made to pipe() that doesn't include operators within it. Does it help in the subscription teardown or something similar?
Both ways convert the subject into an observable. So you convert subjects to observables and expose only the observables to make sure consumers cannot call
next()
and emit values.Update: I have changed it to
asObservable
as I don't want to create this impression. UsingasObservable
is probably the better approach.Yeah, I've seen the usage of "asObservable()" more often.
And I guess that's the best approach. So I've updated the code to reflect the same.
Thanks.