- Source:
- Tutorials:
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 actionTypestring The 'type' property of the dispatched api request action is set to this value
gatewayTypestring The type of gateway to use. These should be one of the strings defined in Injectables.js
pathstring The path to the endpoint to request
entityTypestring The type of entity we expect to retrieve from the API
entityIdstring | 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 }. ThegetIdshould get the id from the new entity. ThefindEntityis used to lookup if the entity already exists in state. It receives a current entity and should returntrueif and only if the entity matches the target entity.
optionsobject Object with optional options
Properties
Name Type Argument Default Description requestDataobject <optional>
null Object with data to send with the API request
requestOptionsobject <optional>
{} Object with additional options passed to the gateway. Please see gateway documentation for more info
updateEntityViewstring | 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:
targetPath to the entityViewReducerimmediateUpdateIf true, will perform the update immediately, even if the request has not yet completed. Defaults totrue. Ignored ifentityIdis an object
cachingboolean | 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:
entityAn entity in the existing redux state (if it exists)entityTypeThe entityType passed to this callentityIdThe entityId passed to this call Should return false if the call should be aborted, true if the request should be executed normally.
Returns:
A Promise that resolves with an object of the following shape:
- entity The entity data
- fromCache
trueif 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 entityobject <optional>
The entity that already exists in state, if it exists
Returns:
False if the caching is valid and the call should be aborted
- Type
- boolean