UNPKG

callyflower

Version:

A collection of lightweight higher order functions to add customizable event handling to a function execution flow.

15 lines (14 loc) 987 B
import { OnCallHandler } from "./types"; /** * Wraps a function with an `onCall` event handler, allowing modification of the function's arguments. * The returned function calls the original function and applies the `onCall` event beforehand. * It can be used to modify the arguments before the function is called, or to short-circuit the function call. * This is useful for validation, logging, memoization or other pre-processing tasks. * * @template F - The type of the function to wrap. * @param {F} callee - The original function to wrap. * @param {OnCallHandler<F>} onCall - The handler invoked before the function call to modify the arguments. * @returns {F} A new function that wraps the original function with the `onCall` event handler. */ declare const withOnCall: <F extends (...args: any) => any>(callee: F, onCall?: OnCallHandler<F>) => F | ((...args: Parameters<F>) => ReturnType<F>) | ((...args: Parameters<F>) => Promise<ReturnType<F>>); export { withOnCall };