I'm creating an angular application and created 3 simple crud operations. I've used ngrx for state management and it works nicely. I've subscribed to some slices of the states of each crud like
createUserLoaded$.subscribe(loaded => this.showSuccessNotification());
All is working good. I'm subscribing to these observables on ngOnInit of the respective component and unsubscribing all of them again on ngOnDestroy.
But the problem is, when I create a user, go to another route and come back to the create user route back, it shows me the success notification. The reason is last state of createUserLoaded$ that was true and the respective component again subscribes to it.
So I wanted the opinion from the community that should I reset the reducer to its initial state again? Is it a good practice? or what else I should do?
asyncpipe and forget about subscriptions to state. you pass your slices (which are observables) to your properties usingasyncpipe and it does subscription management for you. - dee zgCreateUserPendingandCreateUserErrorflags in state. When http request for creating user starts i setCreateUserPending=true. When the respond comes back i setCreateUserPending=falseand result: if error thenCreateUserError=whateverErrorServerReturnedor if 200 OK just set actual created user slice (or just redirect somewhere else, depends on your ux logic). When i enter component, i list users and set errors to null but that highly depends on your ux workflow how and when you show what messages. - dee zg