Data Containers
Introduction
This layer carries out the state management, API call, and API response mapping processes for the application. For state management, Redux is used with thunk middleware.
The data containers exported in the dataContainers/index.js
path are sent to the createApp function as a parameter with the dataContainers key. The Redux store is created with the dataContainers sent with the createApp function parameter.
Concept Definitions
Actions
Redux actions are defined. A new class is created in the base action class and exported. Click for the base actions list.
Example
Constants
Redux action types are defined. A new instance is created in the base action class and exported. Click for the base constants list.
Example
Model - Mappers
API responses are mapped based on integration maps configs. Base model is imported, and a new class is created with base maps and exported.
Click for the base models list.
Example
Model Binders
The action types in the redux are mapped with the functions in model-mappers, and the action’s payload is sent to the mapper function as a parameter. A new instance is created in the base model binders class and exported.
Click for the base model binders list.
Example
Reducer
Redux reducers are defined.
A new instance is created in the base reducer class. The new instance is exported from the framework with the convertReducer utils.
Click for the base reducers list.
Example
Create New Container
Below is an example where data containers are created for the search feature.
The following folder structure is created in the dataContainers path for the custom container.
constants/index.js
Redux action types are exported.
actions/index.js
Redux actions are defined for the API call.
modelBinders/index.js
Redux action types are mapped with the model mapper functions. If the defined action type is dispatched, the action payload is sent to the function as a parameter.
model/index.js
The class instance or object including the functions defined in modal binders must be exported. The data retrieved from the action payload is sent to the function as a parameter. The API response is standardized with integration maps configs, and modeled data is sent to reducer with the data key.
reducer/index.js
A class is created for the redux reducer, and this class must have a function named handleAction.
Modeled action is sent to the handleAction function as a parameter. The created class instance is exported with the convertReducer function.
index.js
The data container must be initialized and exported from the BaseContainer class with the keys seen below.
Extend Framework Container
Base containers may not always fulfill requirements, and they can be expanded based on needs.
Exemplary Scenario:
The order cancel action within the application does not fulfill the needs of the customer. Order ID should be sent at the end of the URL instead of within the request body.
It’s possible to make the necessary changes to meet the customer’s needs by overriding the postCancelForm function in the OrderActions class.
Here’s how to update the constants class created to add a new constant:
Was this helpful?