1. Getting Started
2. Basic Concepts
3. Handlers
3.0.1 Introduction3.0.2 Data Handler# Data Handler without filter# Data Handler with filter# Data Handler with Multi-filter# Things to Remember# Data Handler Function - Api3.0.3 Infinite Handler3.0.4 Update Handler3.0.5 Update Key Handler3.0.6 Delete Handler3.0.7 Delete Key Handler3.0.8 Splice Handler3.0.9 Custom Handler3.1.0 Toggle Key Handler3.1.1 Dont Update Data Handler3.1.2 callback Handler3.1.3 Dont Update Handler
4. Advanced Concepts
Data Handler
# Data Handler without filter
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: "Data-Handler",},});
# Data Handler with filter
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: "Data-Handler",},filter: ["name"],});
# Data Handler with Multi-filter
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: "Data-Handler",},filter: [["filter-1"], ["filter-2"], ["filter-2"]],});
# Things to Remember
-Adding multiple filters will create multiple copy of the same data.-It will helps to handle different types of data in same api..such as variable kind of filters.Note:-Data-handler is default handler.-No need specify the handler if you want to execute a data handler task.
# Data Handler Function - Api
Important:- The code below are the built in handler function.- Don't copy and paste this handler, it is already available with this hoc.- You will learn how to create your own custom handler in below.- If you want to customize this handler you can do it.
import {generateTimeStamp,updateIn,getIn,Safe,} from "react-boilerplate-redux-saga-hoc";const _checkIsNotObject = (data) =>Object.prototype.toString.call(data) !== "[object Object]";export const dataHandler = ({task: { clearData, subKey = [] } = {},callback: { updateCallback } = {},successData = {},}) => ({ data: oldData = {} } = {}) => ({data: (() => {if (subKey.length > 0) {const _oldCopyData = {...oldData,...successData,[subKey[0]]: oldData[subKey[0]],};return updateIn(_oldCopyData, subKey, (_oldData) => {if (clearData) return Safe(successData, `.${subKey.join(".")}`);return updateCallback? updateCallback(_oldData, Safe(successData, `.${subKey.join(".")}`)): _checkIsNotObject(Safe(successData, `.${subKey.join(".")}`)) ||_checkIsNotObject(Safe(_oldData, `.${subKey.join(".")}`))? Safe(successData, `.${subKey.join(".")}`): newObject(_oldData, Safe(successData, `.${subKey.join(".")}`));});}return updateCallback? updateCallback(oldData, successData): _checkIsNotObject(successData) ||_checkIsNotObject(oldData) ||clearData? successData: newObject(oldData, successData);})(),error: false,lastUpdated: generateTimeStamp(),isInfinite: undefined,infiniteEnd: undefined,isError: false,});