MCPcopy Create free account
hub / github.com/ngrx/platform / entityCacheMetaReducerFactory

Function entityCacheMetaReducerFactory

modules/data/spec/entity-data.module.spec.ts:223–257  ·  view source on GitHub ↗

Create the test entityCacheMetaReducer, injected in tests

(
  collectionCreator: EntityCollectionCreator
)

Source from the content-addressed store, hash-verified

221
222/** Create the test entityCacheMetaReducer, injected in tests */
223function entityCacheMetaReducerFactory(
224 collectionCreator: EntityCollectionCreator
225) {
226 return (reducer: ActionReducer<EntityCache, Action>) => {
227 return (state: EntityCache, action: { type: string; payload?: any }) => {
228 switch (action.type) {
229 case TEST_ACTION: {
230 const mergeState = {
231 Hero: createCollection<Hero>('Hero', action.payload['Hero'] || []),
232 Villain: createCollection<Villain>(
233 'Villain',
234 action.payload['Villain'] || []
235 ),
236 };
237 return { ...state, ...mergeState };
238 }
239 }
240 return reducer(state, action);
241 };
242 };
243
244 function createCollection<T extends { id: any }>(
245 entityName: string,
246 data: T[]
247 ) {
248 return {
249 ...collectionCreator.create<T>(entityName),
250 ids: data.map((e) => e.id),
251 entities: data.reduce((acc, e) => {
252 acc[e.id] = e;
253 return acc;
254 }, {} as any),
255 } as EntityCollection<T>;
256 }
257}
258// #endregion

Callers

nothing calls this directly

Calls 2

createCollectionFunction · 0.70
reducerFunction · 0.50

Tested by

no test coverage detected