All files / src/app/core/store/content/page-tree page-tree.reducer.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7

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 24 25 26 278x   8x     8x           8x         16x 16x               8x  
import { createReducer, on } from '@ngrx/store';
 
import { ContentPageTreeHelper } from 'ish-core/models/content-page-tree/content-page-tree.helper';
import { ContentPageTree } from 'ish-core/models/content-page-tree/content-page-tree.model';
 
import { loadContentPageTreeSuccess } from './page-tree.actions';
 
export interface PageTreeState {
  pagetree: ContentPageTree;
}
 
const initialState: PageTreeState = {
  pagetree: ContentPageTreeHelper.empty(),
};
 
function mergePageTrees(state: PageTreeState, action: ReturnType<typeof loadContentPageTreeSuccess>) {
  const pagetree = action.payload.pagetree;
  return pagetree
    ? {
        ...state,
        pagetree: ContentPageTreeHelper.merge(state.pagetree, pagetree),
      }
    : { ...state };
}
 
export const pageTreeReducer = createReducer(initialState, on(loadContentPageTreeSuccess, mergePageTrees));