Reputation: 349
I use ngrx-store 4.x with effects and Angular 5.
I have a simple use case where I need to show a notification when data has been successfully saved in the backend.
Currently I'm not sure what's the best way to achieve this. I see two options:
I see a potential problem in options 2: If the request takes a very long time, the user could navigate away from the component and come back again, if the request then finishes, the saved notification would suddenly appear.
Both options look a bit overcomplicated to me - could somebody point me in the right direction?
Upvotes: 0
Views: 1657
Reputation: 1097
In your effect when backend service call is handled successfully dispatch related success action.
You could have effect mapping those success actions into notification actions passed to reducer and passed by store selector to the notification component.
You could add that success id into store state. And select from that store state property in your component filtering by your current entity´s id. Something like this is handled shown in https://youtu.be/vX2vG0o-rpM?t=745
Personally I'd go with option 1. since that decouples notifications from the actual component enabling easier swapping, refactoring of notification component if needed.
Upvotes: 4