Modules: apiGetCollection

Members


<static, constant> GET_NEXT :Symbol

Can be passed as a value for offset in apiGetCollection to automatically get the next set we don't have yet

Type:
  • Symbol
Source:

<static, constant> GET_PREVIOUS :Symbol

Can be passed as a value for offset in apiGetCollection to automatically get the previous set we don't have yet

Type:
  • Symbol
Source:

<static, constant> IDENTITY_TRANSFORM :function

Default transform for the api response. Leaves the data untouched

Type:
  • function
Source:

Methods


apiGetCollection(actionType, gatewayType, path, collectionId [, paginationOptions] [, options])

Performs an API request to get a list of entities.

Parameters:
Name Type Argument Description
actionType string

The type property of the dispatched api request action is set to this value

gatewayType string

The type of gateway to use. These should be one of the strings defined in module:Injectables

path string

The path to the endpoint to request

collectionId string

The ID of the collection to store the data in. Should be obtained from module:collectionIds

paginationOptions GetCollectionPaginationOptions <optional>

Object that contains optional pagination options

options object <optional>

Object with optional options

Properties
Name Type Argument Default Description
requestData object <optional>
null

Object with data to send with the API request. This is merged with any parameters that result from paginationOptions.

requestOptions object <optional>
{}

Object with additional options passed to the gateway. Please see gateway documentation for more info

transformResponse function <optional>

A function that will transform the response before it is processed

entityType string | function <optional>
entity => entity._type

A string that indicates type of entities we expect to retrieve from the API. Can also be a function, that takes a responded entity and returns the type of that entity.

getId function <optional>
entity => entity.id

A function that returns the id for each entity returned from the api. Defaults to reading from the id property on the entity object.

storeEntities function <optional>
true

If false, will not store entities to the entities reducer, but only references to the collection reducer. This is useful when the API returns references only, with no data attached.

caching GetCollectionCachingCallback | false <optional>

A function that manages caching for this request or false to always make a full request. See GetCollectionCachingCallback

updatePaginationView string | object <optional>

If set, will update a collectionPaginationViewReducer to match the paginationOptions passed to this action. Can be a string id of the collectionPaginationViewReducer, or an object with the following properties:

  • target ID of the collectionPaginationViewReducer
  • extend If true, will extend the current pagination instead of replacing it. This can be used when doing infinite-scroll type pagination instead of offset-based.
Source:
Returns:

A Promise that resolves with the entity data

Type
Promise

collectionCachingDefault(paginationOptions, currentCollectionState, requestData, getState, path)

Default caching for apiGetCollection. Will lookup the requested items in the current collection reducer state. When some items already exist, will truncate the request pagination parameters to not include these items. When all items already exist, will cancel the call.

Parameters:
Name Type Description
paginationOptions GetCollectionPaginationOptions

The pagination options passed to apiGetCollection

currentCollectionState object

The state of the collectionReducer. If no state is currently present, this will be undefined

requestData object

The requestData argument of apiGetCollection

getState function

The redux getState function

path string

The api request path. Used for debug logs

Source:
Returns:

The paginationOptions parameter modified for caching

Type
GetCollectionPaginationOptions

collectionCachingNoPagination(paginationOptions [, currentCollectionState])

Simplified caching for apiGetCollection. If any data is present in the current collection state, we consider the list as cached (regardless of the amount of data).

Parameters:
Name Type Argument Description
paginationOptions object

The pagination options passed to apiGetCollection

currentCollectionState object <optional>

The state of the collectionReducer. If no state is currently present, this will be undefined

Source:
Returns:

The paginationOptions parameter modified for caching or false if data was already present

Type
object | boolean

processApiGetCollectionResponse(response, actionType, gatewayType, path, collectionId, paginationOptions, options)

This action will call apiGetCollection, but will leave out doing an API request. Instead, you should provide the response of the request as the first argument to this function. All other arguments are the same as apiGetCollection This action can be used when we already have some response data, but we still want to make use of the apiGetCollection functionality to process that data.

Parameters:
Name Type Description
response object

An object that is the same shape as a response that would come from a collection api call

actionType string

see apiGetCollection

gatewayType string

see apiGetCollection

path string

see apiGetCollection

collectionId string

see apiGetCollection

paginationOptions object

see apiGetCollection

options object

see apiGetCollection

Source: