Angular

NgRx Advanced

Entity adapter, feature states, meta-reducers, router store, component store, effects patterns, error handling

24 interview questionsยท
Senior
1

What is the main role of createEntityAdapter in NgRx?

Answer

The Entity Adapter automatically generates reducers and selectors to manage normalized collections of entities. It provides methods like addOne, addMany, updateOne, removeOne that facilitate manipulation of ID-indexed objects. This avoids manually writing collection management logic and ensures a normalized state for better performance.

2

What data structure does Entity Adapter use to store entities?

Answer

Entity Adapter stores entities in an object with two properties: ids (ordered array of identifiers) and entities (key-value dictionary for O(1) access). This normalized structure avoids duplicates, facilitates updates by ID and optimizes lookup performance. The ids array maintains display order.

3

How to specify a custom sort comparator with Entity Adapter?

Answer

The sort comparator is defined via the sortComparer property when creating the adapter. This function compares two entities and returns a number (negative, zero or positive) to determine their order. If sortComparer is set to false, no automatic sorting is applied and ids maintain insertion or update order.

4

Which Entity Adapter method to use to add or update multiple entities in a single operation?

5

Which predefined Entity Adapter selector retrieves all entities as an array?

+21 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free