I came across an interesting scenario in the ngrx example-app provided on Github. When starting a new project, I always strive to follow the best practices, so I referred to the example app for guidance. In one particular instance within the application, they demonstrate the process of deleting a book entity:
- The component dispatches a request with the action 'removeBook' and includes the 'book' object as payload (selected-book-page.component.ts:40)
- An effect handles this request, and if successful, it triggers the 'removeBookSuccess' action which ultimately removes the book from the store (collection.effects.ts:65)
However, if the removal fails, it triggers the 'removeBookFailure' action which has a similar handling mechanism as 'addBookSuccess'. Is this additional step necessary? Considering that the book was never actually removed in the first place, I'm wondering if there's something crucial I might be overlooking here.
on(
CollectionApiActions.addBookSuccess,
CollectionApiActions.removeBookFailure,
(state, { book }) => {
if (state.ids.indexOf(book.id) > -1) {
return state;
}
return {
...state,
ids: [...state.ids, book.id],
};
}
),
If anyone can shed some light on this issue, I would greatly appreciate it!