There are a couple syntax options for dealing with delete
being a reserved word:
- Pass a string for the function name to the
call
method
- Get a reference to the
delete
function in a variable with a different name
Both options are shown below.
For chained functions, you just split the chain into the separate calls and use the result from one call to execute the next call. I have included an example of doing chained calls after the two delete
examples.
import { call } from "redux-saga/effects";
const refResponse = {
remove: () => {
console.log("You removed me!");
}
};
const action = {
user: {
delete: () => {
console.log("You deleted me!");
}
}
};
const database = {
ref: () => {
console.log("Returning ref");
return refResponse;
}
};
export const starter = function*() {
console.log("before call");
yield call([action.user, "delete"]);
console.log("after call using string for function name");
const deleteFunc = action.user.delete;
yield call([action.user, deleteFunc]);
console.log("after call using function variable");
console.log("before start of chained call");
const result = yield call([database, "ref"]);
console.log("before 2nd part of chained call");
yield call([result, "remove"]);
};
