What is @ngrx/entity?
@ngrx/entity is a library for managing collections of entities within an Angular application. It provides a set of methods and utilities to simplify the process of managing entity collections, including CRUD operations, sorting, and filtering.
What are @ngrx/entity's main functionalities?
Entity Adapter
The Entity Adapter is a core feature of @ngrx/entity. It provides methods to manage a collection of entities, including adding, updating, and removing entities.
const adapter = createEntityAdapter<User>();
Selectors
Selectors are used to query the state of the entity collection. @ngrx/entity provides built-in selectors to get all entities, entities as a dictionary, entity IDs, and the total count of entities.
const { selectAll, selectEntities, selectIds, selectTotal } = adapter.getSelectors();
Reducers
Reducers are used to handle actions and update the state. @ngrx/entity provides utility functions to create reducers that can handle adding, updating, and removing entities.
const userReducer = createReducer(initialState, on(addUser, (state, { user }) => adapter.addOne(user, state)));
Other packages similar to @ngrx/entity
redux-toolkit
Redux Toolkit is a package that provides tools to simplify Redux development. It includes utilities for creating slices, which can manage collections of entities similar to @ngrx/entity. However, Redux Toolkit is more general-purpose and can be used with any JavaScript framework, not just Angular.
normalizr
Normalizr is a library for normalizing nested JSON data. It can be used to manage collections of entities by transforming nested data into a flat structure. While it does not provide the same level of integration with state management libraries as @ngrx/entity, it is useful for preparing data to be stored in a state management system.
ngrx-data
NGRX Data is an extension of @ngrx/entity that provides additional features for managing entity collections, including entity services and HTTP data access. It builds on top of @ngrx/entity and provides a higher-level API for common entity operations.