UNPKG

700 BJavaScriptView Raw
1/**
2 * Safe chained function
3 *
4 * Will only create a new function if needed,
5 * otherwise will pass back existing functions or null.
6 *
7 * @param {function} functions to chain
8 * @returns {function|null}
9 */
10export default function createChainedFunction(...funcs) {
11 return funcs.reduce((acc, func) => {
12 if (func == null) {
13 return acc;
14 }
15
16 if (process.env.NODE_ENV !== 'production') {
17 if (typeof func !== 'function') {
18 console.error('Material-UI: Invalid Argument Type, must only provide functions, undefined, or null.');
19 }
20 }
21
22 return function chainedFunction(...args) {
23 acc.apply(this, args);
24 func.apply(this, args);
25 };
26 }, () => {});
27}
\No newline at end of file