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 Handler# Delete Handler without filter# Delete Handler handling array of objects# Delete Handler with filter# Delete Handler with Multi-filter# Delete Handler with Subkey# Delete Handler Function - Api3.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
5. Examples6. Advanced Examples7. ParamsApi ReferenceComplete DocumentationPrevious DocumentationReadme

Delete Handler

# Delete 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-Handler",
},
});

# Delete Handler handling array of objects

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",
id: [1, 2],
key: "id",
},
});

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

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

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

# Delete 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";
export const deleteHandler = ({
task: { key, id, subKey = [] } = {},
successData = {},
}) => ({ data = [] } = {}) => ({
data:
subKey.length > 0
? updateIn(
{
...data,
...successData,
[subKey[0]]: data[subKey[0]],
},
subKey,
(_data) =>
(!Array.isArray(_data) && {}) ||
(Array.isArray(id) &&
_data.reduce(
(acc, curr) =>
id.includes(curr[key]) ? acc : acc.concat([curr]),
[]
)) ||
_data.filter(({ [key]: objId }) => objId !== id)
)
: (!Array.isArray(data) && successData) ||
(Array.isArray(id) &&
data.reduce(
(acc, curr) => (id.includes(curr[key]) ? acc : acc.concat([curr])),
[]
)) ||
data.filter(({ [key]: objId }) => objId !== id),
lastUpdated: generateTimeStamp(),
isError: false,
});