mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-23 13:34:19 +00:00
23 lines
756 B
JavaScript
23 lines
756 B
JavaScript
/**
|
|
* 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.
|
|
*/
|
|
export default function goToOnSuccess(func, history, destination) {
|
|
return async (...args) => {
|
|
let result
|
|
try {
|
|
console.debug("Executing: ", func)
|
|
result = await func(...args)
|
|
console.debug("Executed successfully: ", func, " moving to a different page.")
|
|
history.push(destination)
|
|
return result
|
|
}
|
|
catch(e) {
|
|
console.debug("Execution failed: ", func, ", not doing anything.")
|
|
throw e
|
|
}
|
|
}
|
|
}
|