Replies: 2 comments
-
Sorted entities can be defined as a computed signal: type SortOrder = 'asc' | 'desc';
const UsersStore = signalStore(
withState({ sortOrder: 'asc' as SortOrder }),
withEntities<User>(),
withComputed(({ sortOrder, entities }) => ({
sortedUsers: computed(() => [...entities()].sort(/* ... sorting logic ... */)),
})),
); |
Beta Was this translation helpful? Give feedback.
-
Please correct me if I'm wrong here, but I have concerns around efficiency for this approach on large entity sets. If the entities() passed into withComputed are sorted in a different order than what is desired, the entire entity set would have to be sorted anew each time an entity is added. Ideally, we would have a set of entities which is already sorted on hand, to which new entities could be added, needing only one element to be positioned each time. Is this a valid concern for this approach? Is there a better way of doing this with the existing tools we have (using withEntities)? |
Beta Was this translation helpful? Give feedback.
-
Which @ngrx/* package(s) are relevant/related to the feature request?
signals
Information
The basic store
createEntityAdapter
supports a sort-comparer, which would be nice to have in Signal-StorewithEntities
as well.Describe any alternatives/workarounds you're currently using
New option for
entityConfig
and make collection optional if not required.I would be willing to submit a PR to fix this issue
Beta Was this translation helpful? Give feedback.
All reactions