redux-rest-easy
  • ⛳@brigad/redux-rest-easy
  • docs
    • api
      • reducer
      • createResource
        • actionsConfig
        • actions
        • selectors
      • connect
      • reducer
        • reducers
      • createResource
      • getPersistableState
      • initializeNetworkHelpers
      • reset
    • principles
      • persistence
      • actions
      • selectors
      • preflight
      • reducers
  • LICENSE
  • CHANGELOG
  • CODE_OF_CONDUCT
  • CONTRIBUTING
  • TODO
Powered by GitBook
On this page
  • Dispatch the REQUEST action
  • Execute the beforeHook
  • Perform the request
  • Receive and treat the payload of the request
  • Normalize the payload
  • Dispatch the RECEIVE / FAIL action
  • Execute the afterHook
  • Execute the onSuccess/onFailure
  1. docs
  2. principles

actions

PreviouspersistenceNextselectors

Last updated 6 years ago

This process defines the set of steps performed by redux-rest-easy actions, from the moment the request is performed to the moment we receive the payload.

See for the list of action parameters.

Dispatch the REQUEST action

Dispatching the REQUEST action will trigger the corresponding reducer, and create a key in the store corresponding to the normalized URL of the request, with metadata useful to cache control and selectors. See .

Execute the beforeHook

Specifying an optional function action.beforeHook when defining an action will allow executing this function everytime the preflight checks are passed for this action. If it returns a non-falsy value, the return value will be used as the body for the principal request. Useful to perform series of calls.

Perform the request

The request will be performed using fetch, using the URL action.url specified when defining the action, and the query parameters/body specified when dispatching the action.

Receive and treat the payload of the request

The status code of the answer will be handled, then the payload will be processed to JSON.

Normalize the payload

The payload will be normalized using optional function action.normalizer if there is one (and if the request succeeded). The payload will otherwise be stored as-is.

The payload metadata will be extracted using optional function action.metadataNormalizer if there is one (and if the request succeeded).

Dispatch the RECEIVE / FAIL action

Execute the afterHook

Specifying an optional function action.afterHook when defining an action will allow executing this function every time a request has successfully performed.

Execute the onSuccess/onFailure

Dispatching the RECEIVE action will trigger the corresponding reducer and store the normalized data in the state. See .

Dispatching the FAIL action will trigger the corresponding reducer and update the normalized URL metadata. See .

Last but not least, specifying a onSuccess / onFailure parameter when dispatching an action (e.g. from a component) will provide a way to specify callbacks at the component level, and to adapt the UI accordingly. See .

actions documentation
reducers documentation
reducers documentation
reducers documentation
createResource documentation