I am using Angular 8 with @ngrx/data
to manage my entities. When I initiate a delete operation which fails (server returns 500), the entity is removed from the ngrx client side cache, despite it not being deleted on the server.
How do I prevent the entity from being removed from the cache on error? Or how do I re-add the (non-)deleted entity back to the cache on error?
Use pesimistic save https://ngrx.io/guide/data/entity-change-tracker#save-errors
The EntityActions whose operation names end in _OPTIMISTIC start an optimistic save.
Many apps are easier to build when saves are "optimistic" because the changes are immediately available to application code that is watching collection selectors. The app doesn't have to wait for confirmation that the entity operation succeeded on the server.
A pessimistic save doesn't update the store until the server until the server confirms that the save succeeded, which NgRx Data then turns into a "SUCCESS" action that updates the collection. With a pessimistic save, the changes won't be available in the store