mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +08:00
DISABLE_THIRD_PARTY_CHECK=new npm module causes package-lock change We can get rid of a custom script and use ESLint for these rules. Additionally this means editors will highlight the issue in the editor. Change-Id: I552b52e7f07b4e7430b3f685dbc3b5fad36ffff2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2052167 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
import _isArray from './_isArray.js';
|
|
import _isTransformer from './_isTransformer.js';
|
|
|
|
/**
|
|
* Returns a function that dispatches with different strategies based on the
|
|
* object in list position (last argument). If it is an array, executes [fn].
|
|
* Otherwise, if it has a function with one of the given method names, it will
|
|
* execute that function (functor case). Otherwise, if it is a transformer,
|
|
* uses transducer [xf] to return a new transformer (transducer case).
|
|
* Otherwise, it will default to executing [fn].
|
|
*
|
|
* @private
|
|
* @param {Array} methodNames properties to check for a custom implementation
|
|
* @param {Function} xf transducer to initialize if object is transformer
|
|
* @param {Function} fn default ramda implementation
|
|
* @return {Function} A function that dispatches on object in list position
|
|
*/
|
|
export default function _dispatchable(methodNames, xf, fn) {
|
|
return function () {
|
|
if (arguments.length === 0) {
|
|
return fn();
|
|
}
|
|
var args = Array.prototype.slice.call(arguments, 0);
|
|
var obj = args.pop();
|
|
if (!_isArray(obj)) {
|
|
var idx = 0;
|
|
while (idx < methodNames.length) {
|
|
if (typeof obj[methodNames[idx]] === 'function') {
|
|
return obj[methodNames[idx]].apply(obj, args);
|
|
}
|
|
idx += 1;
|
|
}
|
|
if (_isTransformer(obj)) {
|
|
var transducer = xf.apply(null, args);
|
|
return transducer(obj);
|
|
}
|
|
}
|
|
return fn.apply(this, arguments);
|
|
};
|
|
} |