All files / @gce/documents/store reselect.js

100% Statements 11/11
100% Branches 4/4
100% Functions 7/7
100% Lines 8/8

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      3x   3x   3x   1x       3x 8x 9x 5x  
import { createSelector } from 'reselect';
import { FILTER_TYPES } from './constants';
 
const documentSelector = state => state.documents;
 
const filterTypeSelector = state => state.filterType;
 
const filterUnreadSelector = state => state.filterUnread;
 
export const finalDocumentsSelector = createSelector(
  documentSelector,
  filterTypeSelector,
  filterUnreadSelector,
  (documents, filterType, filterUnread) => documents
    .sort((a, b) => new Date(b.date) - new Date(a.date))
    .filter(d => d.documentFilterType === filterType || filterType === FILTER_TYPES.ALL)
    .filter(d => d.seen !== filterUnread || !filterUnread));