Expose selectId
As a Prop When Using withEntities
#4730
Unanswered
JordanW9232
asked this question in
Q&A
Replies: 1 comment 1 reply
-
If you need const todoConfig = entityConfig({
entity: type<Todo>(),
selectId: (todo) => todo.key,
});
const TodosStore = signalStore(
withEntities(todoConfig),
withProps(() => ({ selectId: todoConfig.selectId })),
); create a custom feature const TodosStore = signalStore(
withEntities(todoConfig),
withSelectId(todoConfig.selectId),
); or create a custom feature that wraps const TodosStore = signalStore(
withMyCustomEntities(todoConfig), // uses `withEntities` internally and adds `selectId`
); However, I don't see a significant benefit in doing this. You can directly provide the entity config object to updaters as shown in the official documentation: https://ngrx.io/guide/signals/signal-store/entity-management#entityconfig const todoConfig = entityConfig({
entity: type<Todo>(),
selectId: (todo) => todo.key,
});
const TodosStore = signalStore(
withEntities(todoConfig),
withMethods((store) => ({
addTodo(todo: Todo): void {
patchState(store, addEntity(todo, todoConfig));
},
})),
); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Which @ngrx/* package(s) are relevant/related to the feature request?
signals
Information
When calling
withEntities
with a config like this:I would like the
selectId
function to be populated in the props of the store so I can reference it later. Maybe call itentitySelectId
in theEntityProps<Entity>
type. That way when using one of the entity updaters I could just call it like this:If using a named entity store, then it might look like this:
The
entitySelectId
would then be prepended with the collection specified. LikecustomEntitySelectId
. Then we could use it like this:Describe any alternatives/workarounds you're currently using
In more simple scenarios this isn't really a problem since you can just do this:
But in a more complex scenario when you have a custom store feature that expects
withEntities
to already have been called, you basically need your feature to specify the selectId again:Which you would use like this:
But if it was just attached to the store I wouldn't need the extra parameter in my custom feature. I could just do this:
I would be willing to submit a PR to fix this issue
Beta Was this translation helpful? Give feedback.
All reactions