As a newcomer to reactive programming, I am exploring ways to create an Angular service that can present notifications to the user. Check out what I have accomplished so far:
https://stackblitz.com/edit/angular-rxjs-notifications?file=app%2Fapp.component.html
The main challenge in my implementation lies in figuring out how to queue notifications in a reactive manner. My goal is for the notification div
to display when the first notification is pushed, and disappear only when "Clear" is clicked unless more notifications have been added since. This way, clearing would reveal the next notification, continuing until all notifications are cleared. Subsequently, once a new notification is received, the div should reappear.
In my setup, I opted for a Subject
instead of a ReplaySubject
because I do not want users to see notifications sent while they were loading the next screen. However, I realized that if there is routing within my app.component.html
, this behavior may still occur. Perhaps I need to clear the notification queue upon navigation?
Your insights are greatly appreciated!