2021-05-10 13:22:07 +00:00
|
|
|
/**
|
|
|
|
* Decorator which adds a redirect on success to an event handler.
|
|
|
|
*
|
|
|
|
* @param func - The function to decorate.
|
|
|
|
* @param history - The history to push the destination to.
|
|
|
|
* @param destination - The path of the destination.
|
|
|
|
* @returns {(function(): void)|*}
|
|
|
|
*/
|
|
|
|
export default function goToOnSuccess(func, history, destination) {
|
2021-05-11 16:05:01 +00:00
|
|
|
return (...args) => {
|
|
|
|
let result
|
2021-05-10 13:22:07 +00:00
|
|
|
try {
|
2021-05-14 09:31:14 +00:00
|
|
|
console.debug("Provando ad eseguire: ", func)
|
2021-05-11 16:05:01 +00:00
|
|
|
result = func(...args)
|
|
|
|
history.push(destination)
|
|
|
|
return result
|
2021-05-10 13:22:07 +00:00
|
|
|
}
|
|
|
|
catch(e) {
|
2021-05-14 09:31:14 +00:00
|
|
|
console.debug("Esecuzione fallita: ", func, ", non ha fatto nulla.")
|
2021-05-11 16:05:01 +00:00
|
|
|
throw e
|
2021-05-10 13:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|