1. Getting Started
2. Basic Concepts
3. Handlers
4. Advanced Concepts
Using Subkey for accessing deep object
# Adding filters in Deep Object
Note:-Incase you want to update deep object we can use subkey to navigate to that object
const BASE_URL = "https://example.com/";const DEMO_API_CONFIGURATION = {url: ({ id }) => `${BASE_URL}user/${id}`,method: "GET",responseStatusCode: [900],responseStatusCodeKey: "code",responseDataKey: "data",responseMessageKey: "status",errorMessageKey: "error",};DEMO_API_CONFIGURATION_CALL({task: {name: "Data-Handler",subKey: ["data"],},request: {params: { id: 2 },query: { type: "name" },},filter: ["name"],});/*Example:responseData = { data : { data: { id: 1 } } }storeData = { name: { data: { id: 1 } }*/
Note:- In this case it will store the data in an object with key 'name'
# Deleting key in an deep object
Note:- It is almost similar to update, but instead of updating particular key it will delete the particular key from the object
const BASE_URL = "https://example.com/";const DEMO_API_CONFIGURATION = {url: ({ id }) => `${BASE_URL}user/${id}`,method: "GET",responseStatusCode: [900],responseStatusCodeKey: "code",responseDataKey: "data",responseMessageKey: "status",errorMessageKey: "error",};DEMO_API_CONFIGURATION_CALL({task: {name: "Delete-Key-Handler",subKey: ["data"],id: [1, 2, 3],key: "id",deleteKey: ["name", "age"],},request: {query: { skip: 10, age: [20, 20] },payload: { age: 20 }, // for post callsparamsSerializer: { arrayFormat: "bracket" }, //default: none - refer query-string npm packageparams: { id: 1 },},filter: ["name"],});/*Example:data = { name : { data : { data: [{ id: 1, name: 'name1',age: '13',gender: 'male' },{ id: 1, name: 'name1',age: '12',gender: 'female' }]}}}After executing task:data = { name : { data : { data : [{ id: 1, gender: 'male' },{ id: 2, gender: 'female' }]}}}*/
# Manually Deleting Subkey Data by calling custom task
Note:-Calling custom task will allow us to manipulate data without calling any api..such as adding count,limit,skip..etc
import { HOC, commonConstants, store } from "react-boilerplate-redux-saga-hoc";const { ON_SUCCESS } = commonConstants;const { DEMO_API_CONFIGURATION_CUSTOM_TASK } = props;DEMO_API_CONFIGURATION_CUSTOM_TASK(ON_SUCCESS, {task: {name: "Delete-Handler",subKey: ["data"],id: [1, 2],key: "id",},filter: ["name"],});
# Getting Filter Data from store
import { useMemo } from "react";import { useQuery } from "react-boilerplate-redux-saga-hoc";const {Auth_hoc: {reducerName,reducerConstants: { DEMO_API_CONFIGURATION },},} = props;const [nameDate, ageData] = useQuery(reducerName, [{ key: DEMO_API_CONFIGURATION, filter: ["name"] },{ key: DEMO_API_CONFIGURATION, filter: ["age"] },]);/**nameData returns{ loader, data, latUpdated, isInfinite, isInfiniteEnd }ageData returns{ loader, data, latUpdated, isInfinite, isInfiniteEnd }**/
Next - How to use handlers