To access state data and metadata, redux-rest-easy
provides useful selectors. Creating a resource with createResource will return an object containing a selectors
key, containing the following selectors:
const resource = {
selectors: {
resource: {
getResource: func,
getResourceById: func,
},
actionName1: {
resource: {
couldPerform: func,
isPerforming: func,
hasSucceeded: func,
hasFailed: func,
isValid: func,
couldPerformOnId: func,
isPerformingOnId: func,
hasSucceededOnId: func,
hasFailedOnId: func,
isValidId: func,
},
request: {
getResource: func,
couldPerform: func,
isPerforming: func,
hasSucceeded: func,
hasFailed: func,
isValid: func,
},
},
...,
},
};
Available to any connected component.
Will return the whole resource (or an empty array). Will be denormalized by default, but can be overridden.
Will return the object corresponding to the id passed as a parameter (or null). Will be denormalized by default, but can be overridden.
Available to any connected component.
Will return true
if the action could perform / is performing / has succeeded / has failed on this resource, or if the resource is valid.
Will return true
if the action could perform / is performing / has succeeded / has failed on this resource id, or if the resource id is valid.
Only available to connected components which specifically requested a resource (via dispatch). They will need to pass ownProps as an argument, on top of state.
Will return the resource corresponding to the payload of the request (or an empty array). Will be denormalized by default, but can be overridden.
Will return the metadata corresponding to the payload of the request (or an empty object).
Will return true
if the request (dispatched by the component) could perform / is performing / has succeeded / has failed, or if the associated request is valid.