React Boilerplate Redux Saga Hoc

Search Results

No results for 'N/A'
1. Getting Started
2. Basic Concepts
3. Handlers
3.0.1 Introduction3.0.2 Data Handler3.0.3 Infinite Handler3.0.4 Update Handler3.0.5 Update Key Handler3.0.6 Delete Handler3.0.7 Delete Key Handler# Delete Key Handler without filter# Delete Key Handler with filter# Delete Key Handler with Multi-filter# Delete Key Handler with Subkey# Delete Key Handler Function - Api3.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
5. Examples6. Advanced Examples7. ParamsApi ReferenceComplete DocumentationPrevious DocumentationReadme

Delete Key Handler

Note:
- Delete Key handler is slightly different from Delete handler, but it will delete only particular key in an object or an array of object

# Delete Key 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: "Delete-Key-Handler",
id: [1, 2],
key: "id",
deleteKey: ["age"],
},
});

# Delete Key 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: "Delete-Key-Handler",
id: [1, 2],
key: "id",
deleteKey: ["age"],
},
filter: ["name"],
});

# Delete Key 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: "Delete-Key-Handler",
id: [1, 2],
key: "id",
deleteKey: ["age"],
},
filter: [["filter-1"], ["filter-2"], ["filter-2"]],
});

# Delete Key Handler with Subkey

Note:
- sub key for handling sub level of data in an object
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-Key-Handler",
subKey: ["data"],
id: [1, 2],
key: "id",
deleteKey: ["age"],
},
filter: [["filter-1"], ["filter-2"], ["filter-2"]],
});

# Delete Key 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 deletedData = (obj, keyArray) =>
Object.keys(obj).reduce(
(acc, curr) =>
(keyArray.includes(curr) && acc) || { ...acc, [curr]: obj[curr] },
{}
);
export const deleteKeyHandler = ({
task: { key, id, deleteKey = [], subKey = [] } = {},
callback: { updateCallback } = {},
successData = {},
}) => ({ data = {} } = {}) => ({
data:
subKey.length > 0
? updateIn(
{
...data,
...successData,
[subKey[0]]: data[subKey[0]],
},
subKey,
(_Data) =>
updateCallback
? updateCallback(_Data, successData) || _Data
: (!Array.isArray(_Data) && deletedData(_Data, deleteKey)) ||
(Array.isArray(id) &&
_Data.reduce(
(acc, curr) =>
id.includes(curr[key])
? acc.concat([deletedData(curr, deleteKey)])
: acc.concat([curr]),
[]
)) ||
_Data.map((_data) =>
_data[key] === id ? deletedData(_data, deleteKey) : _data
)
)
: updateCallback
? updateCallback(data, successData) || data
: (!Array.isArray(data) && deletedData(data, deleteKey)) ||
(Array.isArray(id) &&
data.reduce(
(acc, curr) =>
id.includes(curr[key])
? acc.concat([deletedData(curr, deleteKey)])
: acc.concat([curr]),
[]
)) ||
data.map((_data) =>
_data[key] === id ? deletedData(_data, deleteKey) : _data
),
lastUpdated: generateTimeStamp(),
isError: false,
});