Contains the function
makeCollectionSelector
that can be used to select all the entities in a collection from redux state.
Members
-
<constant> EMPTY_ARRAY :Array
-
Create a const empty result to make sure the reference doesn't change every time
Type:
- Array
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. UsemakeCollectionSelectorto create a selector instead. -
makeCollectionSelector()
-
Returns a new reselect selector that can be used to get all the entities referenced in a collection.
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
makeCollectionSelectorParameters:
Name Type Description stateObject The current redux state
propsObject Properties
Name Type Description collectionIdstring The id of the collection to get. Should be one of the ids defined in
collectionIdsReturns:
An object containing the selector data. See
CollectionSelectorResult- Type
- CollectionSelectorResult
-
CollectionSelectorResult
-
Result returned by a
collectionSelector- Source:
Properties:
Name Type Description entitiesArray.<Object> An array of entity data, if found in the
entitiesSelectorentityRefsArray.<Object> An array of entities in the collection
entityRefs[].idstring The id of the entity
entityRefs[].typestring 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 theentitiesarray, but it is also provided here for conveniencepaginationobject Object containing data pagination info
Properties
Name Type Description typestring One of the pagination types defined in the
paginationTypemoduletotalnumber The total number of entities available on the server. This may be smaller than the amount of entities currently loaded!
offsetnumber (offset type only) The offset of the first entity of the
entitiesarray.atBeginboolean (partition type only)
trueif we know that there are no more entities on the server that come before theentitiesarrayatEndboolean (partition type only)
trueif we know that there are no more entities on the server that come after theentitiesarray