mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-23 00:45:16 +00:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.map = map;
|
||
|
exports.forEach = forEach;
|
||
|
|
||
|
var _react = _interopRequireDefault(require("react"));
|
||
|
|
||
|
/**
|
||
|
* Iterates through children that are typically specified as `props.children`,
|
||
|
* but only maps over children that are "valid elements".
|
||
|
*
|
||
|
* The mapFunction provided index will be normalised to the components mapped,
|
||
|
* so an invalid component would not increase the index.
|
||
|
*
|
||
|
*/
|
||
|
function map(children, func) {
|
||
|
var index = 0;
|
||
|
return _react.default.Children.map(children, function (child) {
|
||
|
return /*#__PURE__*/_react.default.isValidElement(child) ? func(child, index++) : child;
|
||
|
});
|
||
|
}
|
||
|
/**
|
||
|
* Iterates through children that are "valid elements".
|
||
|
*
|
||
|
* The provided forEachFunc(child, index) will be called for each
|
||
|
* leaf child with the index reflecting the position relative to "valid components".
|
||
|
*/
|
||
|
|
||
|
|
||
|
function forEach(children, func) {
|
||
|
var index = 0;
|
||
|
|
||
|
_react.default.Children.forEach(children, function (child) {
|
||
|
if ( /*#__PURE__*/_react.default.isValidElement(child)) func(child, index++);
|
||
|
});
|
||
|
}
|