In my angular app, I have a user service, an activeUser$ behaviorSubject and a loggedIn$ one which will be true or false based(piped(mapped)) on the value of activeUser$. When loggedIn$’s next value is true and then false, that would mean that the user has logged out. There is a function which I want to trigger only when it is true and then false. A loggedOut$ observable as a result would be awesome! Any idea?
Just found out the answer I needed from here
I have implemented it like this:
loggedOut$ = this.loggedIn$.pipe(
distinctUntilChanged(),
map((current) => !current)
);