Skip to content

Latest commit

 

History

History
106 lines (58 loc) · 7.09 KB

README.md

File metadata and controls

106 lines (58 loc) · 7.09 KB

REST Actions

API

createRequestActions

Creates request, success and fail action creators to handle the REST request.

Parameters

  • collection string The name of the collection.
  • verb string The verb defining the request type (find, findOne, create, update, delete).

Returns RequestActions An object containing the request, success and fail action creators.

createReducerActions

Creates action creators to manage the state slice of the collection (e.g. clear to clear entities, clearErrors to clear errors, etc.).

Parameters

  • collection string The name of the collection.

Returns object And object containing the clear and clearErrors action creators.

createRestActions

Creates REST action creators (request, success and fail) for each verb of that collection and action creators to manage the state slice of the collection.

Parameters

  • config object The configuration object, { collection: string, verbs: [string] }, where the collection key is the name of the collection and the verbs is an array of verb (find, findOne, create, update or delete) for which the REST actions will be generated.

Returns object An object containing the REST action creators corresponding to each verb and the reducer action creators.

handlerCreator

Creates the handler function to handle the REST request actions (request, success and fail).

Parameters

  • verb string The verb to handle (find, findOne, create, update or delete).
  • requestActions RequestActions An object containing the request, success and fail action creators to handle.
  • idPath IdPath 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

  • config object 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

  • reducerSubState object the part of the state handled by the REST reducer.
  • options object?= getEntitiesOptionsDefault the options may contain: immutable (boolean, defaults to true) to define if JS (requires a toJS conversion) 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

  • reducerSubState object the part of the state handled by the REST reducer.
  • key string the key of the entity to retrieve (the value returned by the specified idPath).
  • options object?= 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

  • reducerSubState object the part of the state handled by the REST reducer.
  • type string one of finding, findingOne, creating, updating or deleting.
  • key string (optional) - the key of the entity (the value returned by the specified idPath).

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. undefined is 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.