Closed markostanimirovic closed 1 week ago
signals
To use @ngrx/signals/entities plugin with custom configuration, we usually repeat the same properties multiple times:
@ngrx/signals/entities
const selectTodoId = (todo: Todo) => todo._id; const TodosStore = signalStore( withEntities({ entity: type<Todo>(), collection: 'todo' }), withMethods((store) => ({ addTodo(todo: Todo): void { patchState( store, addEntity(todo, { collection: 'todo', selectId: selectTodoId }) ); }, setTodos(todo: Todo[]): void { patchState( store, setEntities(todo, { collection: 'todo', selectId: selectTodoId }) ); }, }) );
With the entityConfig function, the same store will look like this:
entityConfig
const todoConfig = entityConfig({ entity: type<Todo>(), collection: 'todo', selectId: (todo) => todo._id, }); const TodosStore = signalStore( withEntities(todoConfig), withMethods((store) => ({ addTodo(todo: Todo): void { patchState(store, addEntity(todo, todoConfig)); }, setTodos(todo: Todo[]): void { patchState(store, setEntities(todo, todoConfig)); }, }) );
The todoConfig object can be defined as follows:
todoConfig
const todoConfig = { entity: type<Todo>(), collection: 'todo', selectId: (todo) => todo._id, } as const;
However, with dedicated function, type safety will be ensured.
Which @ngrx/* package(s) are relevant/related to the feature request?
signals
Information
To use
@ngrx/signals/entities
plugin with custom configuration, we usually repeat the same properties multiple times:With the
entityConfig
function, the same store will look like this:Describe any alternatives/workarounds you're currently using
The
todoConfig
object can be defined as follows:However, with dedicated function, type safety will be ensured.
I would be willing to submit a PR to fix this issue