selectors
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,
},
},
...,
},
};Resource
Available to any connected component.
getResource(state, applyDenormalizer = true): array<object>
getResource(state, applyDenormalizer = true): array<object>Will return the whole resource (or an empty array). Will be denormalized by default, but can be overridden.
getResourceById(state, id, applyDenormalizer = true): object
getResourceById(state, id, applyDenormalizer = true): objectWill return the object corresponding to the id passed as a parameter (or null). Will be denormalized by default, but can be overridden.
Action.resource
Available to any connected component.
couldPerform(state): bool
couldPerform(state): boolisPerforming(state): bool
isPerforming(state): boolhasSucceeded(state): bool
hasSucceeded(state): boolhasFailed(state): bool
hasFailed(state): boolisValid(state): bool
isValid(state): boolWill return true if the action could perform / is performing / has succeeded / has failed on this resource, or if the resource is valid.
couldPerformOnId(state, id): bool
couldPerformOnId(state, id): boolisPerformingOnId(state, id): bool
isPerformingOnId(state, id): boolhasSucceededOnId(state, id): bool
hasSucceededOnId(state, id): boolhasFailedOnId(state, id): bool
hasFailedOnId(state, id): boolisValidId(state, id): bool
isValidId(state, id): boolWill return true if the action could perform / is performing / has succeeded / has failed on this resource id, or if the resource id is valid.
Action.request
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.
getResource(state, ownProps, applyDenormalizer = true): array<object>
getResource(state, ownProps, applyDenormalizer = true): array<object>Will return the resource corresponding to the payload of the request (or an empty array). Will be denormalized by default, but can be overridden.
getMetadata(state, ownProps): object
getMetadata(state, ownProps): objectWill return the metadata corresponding to the payload of the request (or an empty object).
couldPerform(state, ownProps): bool
couldPerform(state, ownProps): boolisPerforming(state, ownProps): bool
isPerforming(state, ownProps): boolhasSucceeded(state, ownProps): bool
hasSucceeded(state, ownProps): boolhasFailed(state, ownProps): bool
hasFailed(state, ownProps): boolisValid(state, ownProps): bool
isValid(state, ownProps): boolWill return true if the request (dispatched by the component) could perform / is performing / has succeeded / has failed, or if the associated request is valid.
Last updated