Skip to content

Reusable actions

amplifi edited this page Jun 29, 2017 · 1 revision

These actions can be use throughout the client implementation.

Requests

REQUEST_START and REQUEST_DONE should be dispatched whenever an asynchronous request is started or finished. The client application will the display a loading status to the user.

Example use, within an asychronous action:

import Request from '/src/request';
import {requestStart, requestDone} from '/src/actions/router'

export function accountLogout() {
  return dispatch => {
    dispatch(requestStart());

    return Request.post('/account/logout/')
      .then(
        (success => {
          dispatch(postLogoutSuccess(success));
          dispatch(requestDone());
        }),
        (error => {
          dispatch(postLogoutError(error));
          dispatch(requestDone());
        })
      )
  } 
}
Clone this wiki locally