Adding the full CRUD

What we mean by CRUD is the ability to add, edit, read, and delete the data from the store. The point of using the entity library is for it to do most of the heavy lifting. The time has come to revisit our reducer:

// excerpt from app.module.tsfunction userReducer(  state = initial,   action: ActionPayload<User>): State {  switch (action.type) {    case "ADD_USER":      return userAdapter.addOne(action.payload, state);    default:      return state;    }}

Here, we are using the userAdapter instance to carry out adding one item to the store. There is a lot more the adapter can do for us though—here is a full list of its capabilities:

// description of the interface for EntityStateAdapter, // the interface our userAdapter implementsexport 

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.