MCPcopy
hub / github.com/react-bootstrap/react-bootstrap / createChainedFunction

Function createChainedFunction

src/createChainedFunction.tsx:10–29  ·  view source on GitHub ↗

* Safe chained function * * Will only create a new function if needed, * otherwise will pass back existing functions or null. * * @param {function} functions to chain * @returns {function|null}

(...funcs)

Source from the content-addressed store, hash-verified

8 * @returns {function|null}
9 */
10function createChainedFunction(...funcs) {
11 return funcs
12 .filter((f) => f != null)
13 .reduce((acc, f) => {
14 if (typeof f !== 'function') {
15 throw new Error(
16 'Invalid Argument Type, must only provide functions, undefined, or null.',
17 );
18 }
19
20 if (acc === null) return f;
21
22 return function chainedFunction(...args) {
23 // @ts-expect-error ignore "this" error
24 acc.apply(this, args);
25 // @ts-expect-error ignore "this" error
26 f.apply(this, args);
27 };
28 }, null);
29}
30
31export default createChainedFunction;

Callers 2

Collapse.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…