new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Redux Toolkit · API · all subjects

createentityadapter api

17 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Update type for EntityAdapter

Update<T> is an object type with properties: id (EntityId), changes (Partial<T>).

createEntityAdapter function signature and return type

createEntityAdapter is a generic function with signature: createEntityAdapter<T>(options?: {selectId?: IdSelector<T>, sortComparer?: false | Comparer<T>}): EntityAdapter<T>. It accepts optional options for selecting the ID and sorting entities.

EntityAdapter interface methods and properties

EntityAdapter<T> extends EntityStateAdapter<T> and has properties: getInitialState(): EntityState<T> (overloaded to accept additional state), getSelectors(): EntitySelectors<T, EntityState<T>> (overloaded to accept selectState function), selectId (IdSelector<T>), sortComparer (false | Comparer<T>).

EntitySelectors interface methods

EntitySelectors<T, V> has methods: selectAll (state: V) => T[], selectById (state: V, id: EntityId) => T | undefined, selectEntities (state: V) => Dictionary<T>, selectIds (state: V) => EntityId[], selectTotal (state: V) => number.

EntityStateAdapter interface methods - set operations

EntityStateAdapter<T> has setOne and setMany methods with overloads: setOne accepts state and entity T or state and PayloadAction<T>, setMany accepts state and readonly T[] | Record<EntityId, T> or state and PayloadAction<readonly T[] | Record<EntityId, T>>.

EntityStateAdapter interface methods - update operations

EntityStateAdapter<T> has updateOne and updateMany methods with overloads: updateOne accepts state and Update<T> or state and PayloadAction<Update<T>>, updateMany accepts state and ReadonlyArray<Update<T>> or state and PayloadAction<ReadonlyArray<Update<T>>>.

EntityStateAdapter interface methods - upsert operations

EntityStateAdapter<T> has upsertOne and upsertMany methods with overloads: upsertOne accepts state and entity T or state and PayloadAction<T>, upsertMany accepts state and readonly T[] | Record<EntityId, T> or state and PayloadAction<readonly T[] | Record<EntityId, T>>.

EntityStateAdapter interface methods - remove operations

EntityStateAdapter<T> has removeOne, removeMany, and removeAll methods: removeOne accepts state and EntityId or state and PayloadAction<EntityId>, removeMany accepts state and readonly EntityId[] or state and PayloadAction<readonly EntityId[]>, removeAll accepts only state.

EntityState interface structure

EntityState<T> has properties: entities (Dictionary<T>) and ids (EntityId[]).

EntityId type

EntityId is a union type defined as number | string.

Dictionary interface

Dictionary<T> extends DictionaryNum<T> and has index signature [id: string]: T | undefined.

Comparer type for EntityAdapter

Comparer<T> is a type for comparison functions with signature: (a: T, b: T) => number.

IdSelector type for EntityAdapter

IdSelector<T> is a type for functions that extract entity IDs with signature: (model: T) => EntityId.

Entity adapter selectId option is required for non-id fields

createEntityAdapter defaults to expecting an id field on entities. If entities use a different field name for identity (like bookId), pass selectId in the options: createEntityAdapter<Book>({ selectId: (book) => book.bookId }).

Entity adapter getSelectors with injected slices

When using injectInto to lazily load a slice, pass a selector function to getSelectors that retrieves the slice state from the root state: booksAdapter.getSelectors((state) => injectedBooksSlice.selectSlice(state)). This allows entity adapter selectors to work with dynamically injected slices.

createEntityAdapter provides prebuilt reducers and selectors for CRUD on normalized state

createEntityAdapter provides prebuilt reducers and selectors for CRUD operations on normalized state.

createEntityAdapter generates reusable reducers and selectors

createEntityAdapter() generates a set of reusable reducers and selectors to manage normalized data in the store.

Give your agent this brain