Skip to content

Multiple sorted ids arrays by createEntityAdapter #3008

Open
@guswnsxodlf

Description

@guswnsxodlf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions