Is there any reason why certain types, e.g. EntityStateAdapter, EntitySelectors or even simple ones like EntityId are not exported?
If not, I think it might be helpful to expose them. I am writing some wrappers around the new Entity feature where accessing them would be 100% beneficial :)
Just didn't happen to include them in the exports. Seems like it might be useful, yeah. I'll see about exporting them in the next alpha.
What kind of wrappers are you writing, and what use cases are you looking to solve?
Attempting to write some boilerplate reducing wrappers for CRUD management in my app. Here's an example for generating selectors:
export const createEntityCrudSelectorsFor = <T, State>(
adapter: EntityAdapter<T>,
sliceSelector: (state: State) => CrudEntityState<T>
) => {
const entitySelectors = adapter.getSelectors(sliceSelector);
const ids = entitySelectors.selectIds;
const map = entitySelectors.selectEntities;
const list = entitySelectors.selectAll;
const count = entitySelectors.selectTotal;
const byId = createSelector(
map,
(state: State, id: number) => id,
(entitiesMap, id) => entitiesMap[id]
);
const bulkLoading = (state: State) => sliceSelector(state).bulkError;
const bulkError = (state: State) => sliceSelector(state).bulkError;
return { ids, map, list, count, byId, bulkLoading, bulkError };
};
I originally wanted to pass only the selectors from adapter.getSelectors() instead of the entire adapter, but ended up doing this instead. I'd even say it's better.
Still, in some places, access to the above mentioned really would be helpful.
P.S.: My CrudEntityState is an extended EntityState, I added some loading and error handling.
I'm not trying to create anything super generally-useful here, just simplify things in one specific app :)
Forgot to do this in beta.0. I'll do so before the final 1.3 release.
Forgot to do it in 1.3 final, too, but it's done in 1.3.3:
https://github.com/reduxjs/redux-toolkit/releases/tag/v1.3.3