import { EnhancedItem } from '@devhub/core' ; import { EMPTY_ARRAY , EMPTY_OBJ } from '../../utils/constants' ; import { RootState } from '../types' ; import { createShallowEqualSelector } from './helpers' ; const s = ( state ) => state . data || EMPTY_OBJ ; export const dataByNodeIdOrId = ( state ) => s ( state ) . byId ; export const dataNodeIdsOrIdsBySubscriptionId = ( state ) => s ( state ) . idsBySubscriptionId ; export const dataReadIds = ( state ) => s ( state ) . readIds ; export const dataSavedIds = ( state ) => s ( state ) . savedIds ; export const createItemsBySubscriptionIdsSelector = ( ) => { return createShallowEqualSelector ( ( _state , subscriptionIds ) => subscriptionIds , ( state , _subscriptionIds ) => dataNodeIdsOrIdsBySubscriptionId ( state ) , ( state , _subscriptionIds ) => dataByNodeIdOrId ( state ) , ( subscriptionIds , idsBySubscriptionId , entryById ) => { if ( ! idsBySubscriptionId ) return EMPTY_ARRAY ; if ( ! ( subscriptionIds && subscriptionIds . length ) ) return EMPTY_ARRAY ; const itemIds = [ ] ; const items = [ ] ; subscriptionIds . forEach ( ( subscriptionId ) => { const ids = idsBySubscriptionId [ subscriptionId ] ; if ( ! ( ids && ids . length ) ) return ; ids . forEach ( ( id ) => { if ( ! id ) return ; if ( itemIds . includes ( id ) ) return ; const entry = entryById [ id ] ; if ( ! ( entry && entry . item ) ) return ; itemIds . push ( id ) ; items . push ( entry . item ) ; } ) ; } ) ; if ( ! ( items && items . length ) ) return EMPTY_ARRAY ; return items ; } ) ; } ;