Modules: apiGetEntity

Methods


apiGetEntity(actionType, gatewayType, path, entityType, entityId, options)

Performs an API request to get a single entity. Checks if the given entity type already exists in the state. If so, this action will skip the request and resolve immediately (unless the useCache parameter says otherwise). When the API responds, will automatically put the response on the relevant redux state.

Parameters:
Name Type 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 Injectables.js

path string

The path to the endpoint to request

entityType string

The type of entity we expect to retrieve from the API

entityId string | object

Either of the following:

  • The string id of the entity we expect to retrieve from the API
  • An object with the shape { findEntity: function, getId: function }. The getId should get the id from the new entity. The findEntity is used to lookup if the entity already exists in state. It receives a current entity and should return true if and only if the entity matches the target entity.
options object

Object with optional options

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

Object with data to send with the API request

requestOptions object <optional>
{}

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

updateEntityView string | object <optional>

If set, will update a entityViewReducer to match the entityId and entityType passed to this action. Can be a string path to the entityViewReducer, or an object with the following properties:

  • target Path to the entityViewReducer
  • immediateUpdate If true, will perform the update immediately, even if the request has not yet completed. Defaults to true. Ignored if entityId is an object
caching boolean | function <optional>
entityCachingDefault

A function that determines if there is still a valid cached entity for the requested type and id. Takes the following parameters:

  • entity An entity in the existing redux state (if it exists)
  • entityType The entityType passed to this call
  • entityId The entityId passed to this call Should return false if the call should be aborted, true if the request should be executed normally.
Source:
Returns:

A Promise that resolves with an object of the following shape:

  • entity The entity data
  • fromCache true if the entity data was pulled from cache, false if it comes from a new api response
Type
Promise

entityCachingDefault( [entity])

Default caching for apiGetEntity. If the requested entity already exists (in any form), will abort the call.

Parameters:
Name Type Argument Description
entity object <optional>

The entity that already exists in state, if it exists

Source:
Returns:

False if the caching is valid and the call should be aborted

Type
boolean