-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customized Id property #85
Comments
Not at the moment, but it can be added, will investigate how big can the change be |
Ok this is what I found, my original idea was to add a new optional prop idKey, to all withEntities* , and this will need to be passed on to each in the same way that collection is passed, there are a few problems with this approach, for one not all of the withEntities need to change the entities so they dont all need the idKey prop, and because is optional it can cause mistakes, because a dev could forget to pass it to all withEntities that need it. The second approach create my own withEntities something like withEntitiesCustomId({idKey, collection?}) this just stores the idKey in the store and then any withEntities* after it can used if present, this is what I'm considering at the moment |
+1 would really need this customized Id property. I really hope you will add this functionality. Let us know and thank you for your work! |
@sasobunny definitely will support this, there are some new changes coming in ngrx/signals 18 that will help me solve this |
Good news, I have it worlking, will be comming soon, first to the beta channel
Essentially you just need to create entityConfig as shown above and be sure to add as const, and then spread it in each withEntities store feature |
@jmls @sasobunny this is now available in 17.9.0-beta.3 |
🎉 This issue has been resolved in version 17.9.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
One last comment, like I mentioned there are breaking changes related to custome id in ngrx/signals 18 currently in RC 2, Im already preparing support for it, and changes for ngrx-traits will be in the beta channel soon in version 18 of this lib, which will require also angular 18 and ngrx/signals 18, basically, ngrx/signals 18 replaces idKey for selectId and adds a function called entityConfig example of how it will look in version 18 const config = entityConfig({
entity: type<ProductCustom>(),
collection: 'products',
selectId: (entity) => entity.productId, // <-- idKey is replaced by selectId function
});
export const ProductsLocalStore = signalStore(
{ providedIn: 'root' },
withEntities(config),
withCallStatus({ ...config, initialValue: 'loading' }),
withEntitiesLocalPagination({
...config,
pageSize: 5,
}),
withEntitiesLocalFilter({
...config,
defaultFilter: { search: '' },
filterFn: (entity, filter) =>
!filter?.search ||
entity?.name.toLowerCase().includes(filter?.search.toLowerCase()),
}),
withEntitiesLocalSort({
...config,
defaultSort: { field: 'name', direction: 'asc' },
}),
withEntitiesSingleSelection({
...config,
}),
withEntitiesLoadingCall({
...config,
fetchEntities: ({ productsFilter }) => {
return inject(ProductService)
.getProducts({
search: productsFilter().search,
})
.pipe(
map((d) =>
d.resultList.map(({ id, ...product }) => ({
...product,
productId: id,
})),
),
);
},
}),
); |
🎉 This issue has been resolved in version 17.9.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
ngrx/signalstore supports entities with custom id fields
https://ngrx.io/guide/signals/signal-store/entity-management#customized-id-property
If I try and pass a type that doesn't have the
id
field defined, then I get a compile error with withEntitiesSingleSelection , withEntitiesMultiSelection and withEntitiesLocalFilter saying"not assignable to type '{ id: string | number; }'."
doess ngrx-traits alllow for custom id fields ?
The text was updated successfully, but these errors were encountered: