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 Handler3.0.8 Splice Handler3.0.9 Custom Handler3.1.0 Toggle Key Handler3.1.1 Dont Update Data Handler3.1.2 callback Handler# Things to Remember# Callback Handler without filter# Callback Handler with filter# Callback Handler with Multi-filter# Callback Handler Function - Api3.1.3 Dont Update Handler
4. Advanced Concepts
5. Examples6. Advanced Examples7. ParamsApi ReferenceComplete DocumentationPrevious DocumentationReadme

Callback Handler

# Things to Remember

- This handler won't update only data.
- But it will update loaders,error state, and also toast.
- This handler will work only on api calls and custom task.

# Callback 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: "Callback-Handler",
callback: (previousData, responseData, rest: {statusCode, ...rest} = {}, status) => ({
loading: null,
data: status === 200 ? [...previousData, ...responseData] : responseData,
}),
},
});

# Callback 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: "Callback-Handler",
callback: (previousData, successData, rest: {statusCode, ...rest} = {}, status) => ({
loading: null,
data: status === 200 ? [...previousData, ...successData] : previousData,
}),
},
filter: ["name"],
});

# Callback 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: "Callback Handler",
callback: (previousData, successData, rest: {statusCode, ...rest} = {}, status) => ({
loading: null,
data: status === 200 ? [...previousData, ...successData] : previousData,
}),
},
filter: [["filter-1"], ["filter-2"], ["filter-2"]],
});

# Callback Handler Function - Api

Note:
- 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 invariant from "invariant";
import { typeOf } from "../helpers";
const checkKey = (callback) => {
invariant(
typeOf(callback) === "function",
`(react-boilerplate-redux-saga-hoc) ${
typeof callback === "undefined"
? "'Callback-Handler' required callback key"
: "callback is not a function"
}`
);
};
export const callbackHandler = ({
task: { callback } = {},
successData = {},
successDataStatusCode,
}) => ({ data: oldData = {}, statusCode, ...rest } = {}) => {
checkKey(callback);
return callback({
oldData: oldData,
newData: successData,
rest: { ...rest, statusCode },
status: statusCode || successDataStatusCode,
});
};