UNPKG

@carbon/react

Version:

React components for the Carbon Design System

33 lines (28 loc) 925 B
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * Composes multiple event handler functions into a single event handler. The * composed handler calls each provided function sequentially with the event and * any additional arguments. If any handler calls `event.preventDefault()`, * further handlers are skipped. * * @param handlers - An array of event handler functions. * @returns A composite event handler. */ const composeEventHandlers = handlers => (event, ...args) => { for (const handler of handlers) { if (event.defaultPrevented) { break; } if (typeof handler === 'function') { handler(event, ...args); } } }; exports.composeEventHandlers = composeEventHandlers;