В ответ на ответ Тима я посмотрел за пределы поля ngrx / entity. Я не должен был сосредоточиться на использовании его в первую очередь, так как ответ был довольно прост.
Я добавил интерфейс, который содержит строку и число. В своем коде я назвал этот ReportCount. Затем в действии loadsuccess я либо добавляю новый reportCount с идентификатором пользователя и устанавливаю для счетчика значение 1, либо для счетчика добавляю 1.
В итоге я получил следующий код, который работает, как и ожидалось:
(я публикую это для других людей, которые могут застрять в той же проблеме)
export interface ReportCount{
superintendent: string,
count: number,
};
export interface State {
reportCounts: ReportCount[],
showRegistrations: boolean,
loading: boolean,
loaded: boolean,
};
export const initialState: State = {
reportCounts: [],
showRegistrations: true,
loading: false,
loaded: false,
};
export const reducer = createReducer(
initialState,
on(RegistrationActions.ShowRegistrations,
(state, { setShow }) => ({
...state,
showRegistrations: setShow,
})
),
on(RegistrationSuperintendentsCollectionActions.loadRegistrationSuperintendentCollection, (state) => ({
...state,
loading: true,
})),
on(RegistrationSuperintendentsCollectionApiActions.loadRegistrationSuperintendentsSuccess,
(state, { superintendents }) => {
const repCount: ReportCount[] = [];
superintendents.forEach(superintendent => {
let sup = repCount.find(s => s.superintendent === superintendent);
sup ? (sup.count = sup.count + 1) : repCount.push({superintendent, count:1});
})
return ({
...state,
reportCounts: repCount,
loading: false,
loaded: true
})
}
),
);
export const getShowRegistrations = (state: State) => state.showRegistrations;
export const getLoaded = (state: State) => state.loaded;
export const getLoading = (state: State) => state.loading;
export const getLoadedSuperintendentRegistrations = (state: State) => state.reportCounts;