Skip to content

Multiple sorted ids arrays by createEntityAdapter #3008

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

Open
guswnsxodlf opened this issue Dec 15, 2022 · 1 comment
Open

Multiple sorted ids arrays by createEntityAdapter #3008

guswnsxodlf opened this issue Dec 15, 2022 · 1 comment
Labels
question Further information is requested

Comments

@guswnsxodlf
Copy link

guswnsxodlf commented Dec 15, 2022

Hello,

I am using createEntityAdapter on my app, and I need to sort the entities I got from the server, using many different sort functions.

Currently, createEntityAdapter only supports a single ids array and a single sortcomparer.

I managed this by making different selectors which get the sorted entities array (using selectAll) from the reducer and sort it in a different way.

However, it is not normalized structure since I can't get a sorted ids, but sorted entities.

Is there any way to have multiple ids arrays with a single entities lookup table?

For example,

type Book = { bookId: string; title: string; author: string }

const booksAdapter = createEntityAdapter<Book>({
  selectId: (book) => book.bookId,
  // ids arrays sorted based on book titles, and also on  **author names**.
  sortComparer: [
    sortFuncByTitleAsc,
    sortFuncByAuthorAsc,
  ],
})

Thanks.

@markerikson
Copy link
Collaborator

markerikson commented Dec 15, 2022

There's nothing built in, no. This looks related to #799 .

Note that you could have one sort function that does multiple comparison steps at once.

@aryaemami59 aryaemami59 added the question Further information is requested label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants