All files / src/app/core/store/content/pagelets pagelets.selectors.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 5/5
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  19x 19x     19x 19x   19x   19x   19x   19x 1x   1x     19x 1x  
import { Dictionary } from '@ngrx/entity';
import { createSelector, createSelectorFactory, resultMemoize } from '@ngrx/store';
import { isEqual } from 'lodash-es';
 
import { ContentPagelet } from 'ish-core/models/content-pagelet/content-pagelet.model';
import { createContentPageletView } from 'ish-core/models/content-view/content-view.model';
import { getContentState } from 'ish-core/store/content/content-store';
 
import { pageletsAdapter } from './pagelets.reducer';
 
const getPageletsState = createSelector(getContentState, state => state.pagelets);
 
export const { selectEntities: getContentPageletEntities } = pageletsAdapter.getSelectors(getPageletsState);
 
const getContentPageletMemoized = (pageletId: string) =>
  createSelectorFactory<object, ContentPagelet>(projector => resultMemoize(projector, isEqual))(
    getContentPageletEntities,
    (entities: Dictionary<ContentPagelet>) => entities[pageletId]
  );
 
export const getContentPagelet = (pageletId: string) =>
  createSelector(getContentPageletMemoized(pageletId), createContentPageletView);