REST Reducers
API
handlerCreator
Creates the handler function to handle the REST request actions (request, success and fail).
Parameters
verbstring The verb to handle (find, findOne, create, update or delete).requestActionsRequestActions An object containing the request, success and fail action creators to handle.idPathIdPath The path to the value to identify the REST entities (string, string array, function or string with dot seperaing keys).
Returns object An object containing the functions to handle request, success and fail state change in the reducer.
restReducer
Creates a REST reducer to handle the verbs of the REST action creators.
Parameters
configobject The REST reducer config with the following keys:idPath, the path to the identifier of the requested objects (string, string array, function or string with dot seperaing keys);actions: each key of the object is a verb (find, findOne, create, update or delete) and contains the related REST action creators (request, success and fail);extraHandlers: an object where each key is the action type to handle and each key contains a function to handle the state change for these actions.
Returns Reducer A reducer to handle REST request actions and the extra handlers actions.
getEntities
Gets the entities from the state.
Parameters
reducerSubStateobject the part of the state handled by the REST reducer.optionsobject?= getEntitiesOptionsDefault the options may contain:immutable(boolean, defaults to true) to define if JS (requires atoJSconversion) or immutable objects (better for performance) should be returned;reverse(boolean, defaults to false) to return the objects in reverse order.
Returns oject The entities from the state (immutable list or JS array depending on the configuration).
getEntity
Gets an entity from the state based on its key.
Parameters
reducerSubStateobject the part of the state handled by the REST reducer.keystring the key of the entity to retrieve (the value returned by the specifiedidPath).optionsobject?= getEntityOptionsDefault the options to use.immutable: boolean to specify if the returned object should be immutable (defaults to true).
Returns object The entity (immutable map or JS array depending on the configuration).
getStatus
Gets the status of the request by status type.
Parameters
reducerSubStateobject the part of the state handled by the REST reducer.typestring one offinding,findingOne,creating,updatingordeleting.keystring (optional) - the key of the entity (the value returned by the specifiedidPath).
Returns boolean true if the request is pending, else false.
get
Gets the value within an immutable or JS object.
Parameters
obj(Iterable | Object | undefined) the immutable or JS object.undefinedis returned if it is not defined.path(string | [string]) the key(s) to follow. It can be a string , e.g.'slug', a path in dot notation, e.g.'profile.slug', or an array of strings, e.g.['profile', 'slug'].
Returns any The value within the object following path, or undefined if it does not exist.
handlerCreator
Creates the handler function to handle the REST request actions (request, success, fail).
Parameters
verbstring The verb to handle (find, findOne, create, update or delete).requestActionsRequestActions An object containing the request, success and fail action creators to handle.idPathIdPath The path to the value to identify the REST entities (string, string array, function or string with dot separation).
Returns object An object containing the functions to handle request, success and fail state change in the reducer.
restReducer
Creates a REST reducer to handle the defined actions.
Parameters
configobject The REST reducer config with the following keys:idPath, the path to the identifier of the requested objects (string, array of string or function);actions: the REST actions to handle;extraHandlers: an object where each key is the action type to handle and each key contains a function to handle the state change for these actions.
Returns Reducer A reducer to handle REST requests state changes.
getEntities
Gets the entities from the state.
Parameters
reducerSubStateobject the part of the state handled by the REST reducer.optionsobject?= getEntitiesOptionsDefault the options may contain:immutable(boolean, defaults to true) to define if JS (requires atoJSconversion) or immutable objects (better for performance) should be returned;reverse(boolean, defaults to false) to return the objects in reverse order.
Returns oject The entities from the state (immutable list or JS array depending on the configuration).
getEntity
Gets an entity from the state.
Parameters
reducerSubStateobject the part of the state handled by the REST reducer.keystring the key of the entity to retrieve (the value returned by the specifiedidPath).optionsobject?= getEntityOptionsDefault the options to use.immutable: boolean to specify if the returned object should be immutable (defaults to true).
Returns object The entity (immutable map or JS array depending on the configuration).
getStatus
Gets the status of the request.
Parameters
reducerSubStateobject the part of the state handled by the REST reducer.statusstring one offinding,findingOne,creating,updatingordeleting.keystring (optional) - the key of the entity (the value returned by the specifiedidPath).
Returns boolean true if the request is pending, else false.