Modules: collectionSelector

Contains the function makeCollectionSelector that can be used to select all the entities in a collection from redux state.

Source:

Members


<constant> EMPTY_ARRAY :Array

Create a const empty result to make sure the reference doesn't change every time

Type:
  • Array
Source:

Methods


getEntitiesFromCollection()

Instance of collectionSelector that can be used when memoization is not relevant. This function should NOT be used in the connect() of a component. Use makeCollectionSelector to create a selector instead.

Source:

makeCollectionSelector()

Returns a new reselect selector that can be used to get all the entities referenced in a collection.

Source:
Returns:

The new selector. See collectionSelector

Type
collectionSelector
Example
const connector = connect(
  () => {
   const collectionSelector = makeCollectionSelector();

   return (state, { discussionId }) => {
     const comments = collectionSelector(state, {
       collectionId: communityCommentsCollectionId(discussionId, false),
     });

     return {
       comments: comments.entities,
       hasMore: (comments.pagination.total !== null) && (
         comments.pagination.total > comments.entities.length
       ),
     };
   };
  }
);

Type Definitions


collectionSelector(state, props)

Selector returned by makeCollectionSelector

Parameters:
Name Type Description
state Object

The current redux state

props Object
Properties
Name Type Description
collectionId string

The id of the collection to get. Should be one of the ids defined in collectionIds

Source:
Returns:

An object containing the selector data. See CollectionSelectorResult

Type
CollectionSelectorResult

CollectionSelectorResult

Result returned by a collectionSelector

Properties:
Name Type Description
entities Array.<Object>

An array of entity data, if found in the entitiesSelector

entityRefs Array.<Object>

An array of entities in the collection

entityRefs[].id string

The id of the entity

entityRefs[].type string

The type of the entity

entityRefs[].data *

The entity data, if found in the entitiesSelector. Note that this is the same object as referenced in the entities array, but it is also provided here for convenience

pagination object

Object containing data pagination info

Properties
Name Type Description
type string

One of the pagination types defined in the paginationType module

total number

The total number of entities available on the server. This may be smaller than the amount of entities currently loaded!

offset number

(offset type only) The offset of the first entity of the entities array.

atBegin boolean

(partition type only) true if we know that there are no more entities on the server that come before the entities array

atEnd boolean

(partition type only) true if we know that there are no more entities on the server that come after the entities array

Source: