@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
34 lines (30 loc) • 861 B
JavaScript
/**
* MSKCC 2021, 2024
*/
/**
* MSKCC DSM 2021, 2023
*/
/**
* Generic utility to compose event handlers so that consumers can supply their
* own event listeners on table components. The default heuristic here is to
* iterate through the given functions until `preventDefault` is called on the
* given event.
*
* @param {Array<Function|undefined>} fns array of functions to apply to the event
* @returns {any}
*/
const composeEventHandlers = fns => function (event) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
for (let i = 0; i < fns.length; i++) {
if (event.defaultPrevented) {
break;
}
const fn = fns[i];
if (typeof fn === 'function') {
fn(event, ...args);
}
}
};
export { composeEventHandlers };