I an using ngrx/data in my app and am trying to figure out how to use the error$ stream to display an error in a component. Basically I am using a modal pop up with a form to create an entity and I am using the error$ stream to display any error that occurs when saving it. The problem I am having is that if an error occurs and it is displayed and the pop up is closed the next time it is opened the previous error is displayed. This is the code for the error$ selector
this.entityActionErrors$ = actions.pipe(
filter(
(ea: EntityAction) =>
ea.payload &&
ea.payload.entityOp &&
ea.payload.entityOp.endsWith(OP_ERROR)
),
shareReplay(1)
);
The problem is with the shareReplay(1). I am trying to figure how to ignore or filter out the previous error when the modal is reopened and the error$ stream is subscribed to again.
Is there a way in rxjs to ignore or filter out the previous emission from a sharedReplay subject?
The solution I came up with was to use a separate Subject for the error message. I did this in the service class I created for the entity.
The problem I was trying to solve was the problem of local component state so while this does work I decided on a different solution. In ngrx/data all of the command methods in the
EntityCollectionServiceBaseclass return an Observable that emits after the store has been updated. So in the component I subscribe to the command method like:This solution works perfectly and keeps this state in the component where it belongs and out of the store.