Reputation: 103
This question concerns the example provided by ngrx example-app (I didn't know if I can post this to their Github page or not...)
So when creating a new project I wanted to follow the best guidelines, that's why I'm checking the example app as a reference. In the application when for example they try to delete a book entity the do the following :
Now the second case is when it fails it will call 'removeBookFailure' also with book object and actually that action will be handled exactly like 'addBookSuccess'
on(
CollectionApiActions.addBookSuccess,
CollectionApiActions.removeBookFailure,
(state, { book }) => {
if (state.ids.indexOf(book.id) > -1) {
return state;
}
return {
...state,
ids: [...state.ids, book.id],
};
}
),
Do we really need to do that? I mean the book in question was never removed to begin with. Or is there something I'm missing here.
Thanks for your help!
Upvotes: 1
Views: 141
Reputation: 15505
It might seem weird, but it serves API failures.
What I do expect, and what is missing, is the removal of the book when the removeBook
action is dispatched.
If the API call succeeds, everything is already handled correctly - but when it fails we should revert the removal of the book.
Upvotes: 1