@antv/f2
Version:
Charts for mobile visualization.
42 lines • 1.43 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import Children from '../children';
// 主要是把function节点,全部转换成string标签节点
function renderJSXElement(element, context, updater) {
if (!element) return element;
var _element = element,
type = _element.type,
key = _element.key,
ref = _element.ref,
props = _element.props,
_element$_cache = _element._cache,
_cache = _element$_cache === void 0 ? {} : _element$_cache;
// render children first
var children = Children.map(props.children, function (child) {
return renderJSXElement(child, context, updater);
});
element = {
type: type,
key: key,
ref: ref,
_cache: _cache,
props: _objectSpread(_objectSpread({}, props), {}, {
children: children
})
};
if (typeof type === 'function') {
// @ts-ignore
var newElement = type(element.props, context, updater);
if (!newElement) return newElement;
// recursive render until type is string
return renderJSXElement(_objectSpread(_objectSpread({}, newElement), {}, {
// 保留原始的key和ref
key: key !== undefined ? key : newElement.key,
ref: ref !== undefined ? ref : newElement.ref
}), context, updater);
}
// return element if type is string
return element;
}
export default (function (element, context, updater) {
return renderJSXElement(element, context, updater);
});