Redux Module

ReduxModule settings

Actions Props

prefix

This prefix will be setted on all actions in this module environment

Type

Required

Default value

string

Yes

-

defaultState

The default data for current state

Type

Required

Default value

Object

No

null

responseMap

This object is for setting the server response.

Default ResponseMapProps

{
  successStatusValue: 'success',
  message: 'message',
  errors: 'errors',
  status: 'status',
  data: 'data',
}

For example:

// Your server answer is 
const serverResponse = {
    result: [],
    errorData: [],
    response_code: 0,
    messageText: null,
};

// Your responseMap should be
const responseMap = {
    data: 'result',
    errors: 'errorData',
    successStatusValue: 0,
    status: 'response_code',
    message: 'messageText',
}

Type

Required

Default value

Object

No

RespnseMapProps

key

The name of the key in which the data will be stored

Type

Required

Default value

string

No

data

name

The action name. Default value depends on the action type, for example if you use createAddAction default value will be CREATE

Type

Required

Default value

string

No

Depends on the action

idKey

This parameter should be used only when using one of this methods createAddAction, createUpdateAction, createDeleteAction . This property is intended to find the desired item by some identifier.

Type

Required

Default value

string

optional

-

apiCall

This is an API call function, that returns a Promise (required). If you want to update the store without a request to the server you can skip this property. For the store update you need to send data the first argument of the action function.

For example

// When you not use apiCall property.
const { updateProductAction } = this.props;
const updatedData = { /* some data */ };

updateProductAction(updatedData); // After action the 'updatedData' saved in the store

Type

Required

Default value

function

No

-

withoutStatus

When no needed have status parameters.

Type

Required

Default value

boolean

No

-

returnResponse

When the server response have not structure and needed get all response data you can use this property.

Type

Required

Default value

boolean

No

-

withoutResponse

When there is no need to store updates after a request to the server.

Type

Required

Default value

boolean

No

-

alternativeResponse

When need use custom logic for response processing.

Type

Required

Default value

Arguments

function

No

-

(response: Object)

alternativeRequest

When need use custom action or dispatch other actions.

const alternativeRequest = (dispatch, callFunctionArguments, actionType) => {
// When you will use this function you need remember
// Need use one of this statuses
const STATUS = 'SUCCES' || 'PENDING' || 'ERROR';

dispatch({
    type: `${actionType}_${STATUS}`,
    payload: {}
});
}

Type

Required

Default value

Arguments

function

No

-

(dispatch: Function, callFunctionArguments: Array, actionType: string)

callback

When need call function after success response.

Type

Required

Default value

Arguments

function

No

-

(response: Object, dispatch: Function)

Methods

Last updated