Can not debounce action within other action in Vuex
This should definate work
import { debounce } from "lodash";
const actions = {
debounceSomeLogging: debounce(({ dispatch }, text) => {
console.log("Inside debounced function.");
dispatch("doRealThing");
}, 1000),
doRealThing({ commit }) {
// Whatever
}
}
As nemesv pointed out in a comment, the debounce
function does not call the inner function. So you need to call the debounce again, like so:
debounce(function() {
console.log("Inside debounced function.");
dispatch("doRealThing");
}, 1000)();
So, in short, it should look like this:
debounce(...)()
instead of like this debounce(...)
.