It would be nice if we entity in our global store?
I have some crud operations, which are very easily done using @ngrx/entity and I want to have it in root-store.
I have tried creating an entity, but schematics did it for forFeature().
NgRx Entity is basically a Dictionary with matching NgRx operators to update/read.
You can always hold an Entity Object in any store that can store a string for example. You can do so by extending the Store if you just need one Entity Object
export interface State extends EntityState<User> {
...
}
or you can create Entity Objects in the Store like
export interface State {
users: EntityState<User>;
books: EntityState<Book>;
}
Both ways you can work with adapters. For the extend version pass the whole State
to the adapter. For the second approach pass the users property to the adapter method and set the result as new value for that property in the state.
Edit
To update the Entity object a adapter is used. Create an adapter and use it in the reducers. A lot more infos about it and code examples can be found at https://ngrx.io/guide/entity/adapter
// adapter definition
export const userAdapter: EntityAdapter<User> = createEntityAdapter<User>();
// reducer call for extended state / first version
on(UserActions.setUsers, (state, { users }): State => userAdapter.setAll(users, state)),